Jump to content

Including script files


Wherry

Recommended Posts

Hello! Can you guys help me? I have file a.lua and b.lua and i need to call functions from b.lua in a.lua. How to do it?

btw: I already tried dofile() loadfile() (MTA says that it's unsafe functions).

also i tried to define variables as global:

b.lua:

x = "Hello World"

a.lua

outputChatBox(x)

This example outputs error too.

And ofcourse i tried to use triggerEvent + addEvent but it's bad.

Thank you!

Edited by Guest
Link to comment

If you make a global variable/function in one script, it will be available in another script of the same resource on the same side.

also i tried to define variables as global:

b.lua:

x = "Hello World"

a.lua

outputChatBox(x)

Are you sure that code in a.lua was executed after b.lua, not before it?

xthepr0mise,Your getRootElement is wrong( nil ) in first file.

Should be root or getRootElement( ).

No, it's not nil. If it was nil, then getRootElement() would be wrong too because nil value can't be called. getRootElement is a function value.

Link to comment

Ah,yeah this is function variable but not called .

Anyway addEventHandler return false.

Are you sure that code in a.lua was executed after b.lua, not before it?

Better use event onResourceStart ( if server side ) and call function.

And do not think about such issues. :)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...