Jump to content

Globals and Require behaviour


Recommended Posts

Hi,

 

this is currently my first time developing a mod for DST, currently I'm trying to figure out how DST handles global variables when including (require) files.

 

This is my issue:

=> modmain.lua...CMod_Header = function (name)    ....endrequire("generic_luck")=> scripts/generic_luck.luaCMod_Header("Generic Luck")

So I create the function CMod_header in the global table, and then require the file generic_luck.lua inside the folder scripts/. At this moment I would expect CMod_Header to be available in the global table, but this is not the case. 

 

Does DST handle the global table differently when including (require) files?

 

What possible workarounds are there?

Link to comment
Share on other sites

This is not working like that.

 

in a nutshell, require will give you access to functions defined in what you "require", or give you the current copy of the table returned by the file you "required".

 

So basically, writing what you did gave you access in your modmain.lua to functions defined in generic_luck.lua

Edited by ZupaleX
Link to comment
Share on other sites

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
 Share

×
  • Create New...