klei100 Posted December 22, 2015 Share Posted December 22, 2015 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 https://forums.kleientertainment.com/forums/topic/61217-globals-and-require-behaviour/ Share on other sites More sharing options...
ZupaleX Posted December 22, 2015 Share Posted December 22, 2015 (edited) 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 December 22, 2015 by ZupaleX Link to comment https://forums.kleientertainment.com/forums/topic/61217-globals-and-require-behaviour/#findComment-700713 Share on other sites More sharing options...
klei100 Posted December 22, 2015 Author Share Posted December 22, 2015 Ahh, I see. The require behaviour is slightly different from what I remember, my bad. Link to comment https://forums.kleientertainment.com/forums/topic/61217-globals-and-require-behaviour/#findComment-700840 Share on other sites More sharing options...
Mobbstar Posted December 23, 2015 Share Posted December 23, 2015 What you are talking about is available as modimport("filepath.lua")All local variables need to be declared in the seperate file again, though. For reference, check out the cute survival plushies mod. Link to comment https://forums.kleientertainment.com/forums/topic/61217-globals-and-require-behaviour/#findComment-701081 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now