Jump to content

Can I use a function declared in fileA.lua in the fileB.lua?


Stanley Sathler

Recommended Posts

Yo guys,

It's a doubt that I have.

I have two files: fileA.lua and fileB.lua, both as server-side. If I declare a functioni in the fileA.lua, can I use it in the fileB.lua?

Example:

// file: fileA.lua 
function myFunction() 
return 10 
end 

// file: fileB.lua 
function anyFunction() 
outputChatBox("Number: " + myFunction) 
end 

Thanks,

Stanley Sathler.

Link to comment

If they are both server/client sided (Same), theorically yes, becouse they are being defined globally.

Idk if there's any difference by calling the function g_functionName. Thought i usually do that for this purpouse. Test it thought.

(Remember one file may load before the other, so add a timer.)

Oh and you did a syntax error

  
// file: fileB.lua 
function anyFunction() 
outputChatBox("Number: " + myFunction()) 
end 

Link to comment
  • Moderators

When the "onResourceStart" event gets executed, all global variables are access able in all 'files'.

You can start calling functions from the other side after this event has been occurred.

It is possible to call them before this event, but you can only call loaded ones.

This depends on which the meta.xml loads first. I won't recommend you this.

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...