Page 1 of 1
Multi file problem
Posted: Sun Jun 28, 2020 2:30 pm
by yagaodirac
1, Is it possible to access functions or variables in another file? Through require directive or something else?
2, Any method to iterate all the custom variables and functions in a scenerio?
3, How to restart mtn fortress with console, without deleting the data.??? file in save file?
Or link to the answers directly.
Thanks.
Re: Multi file problem
Posted: Sun Jun 28, 2020 3:23 pm
by Pi-C
yagaodirac wrote: Sun Jun 28, 2020 2:30 pm
1, Is it possible to access functions or variables in another file? Through require directive or something else?
In
this mod, I've stored different functions and variable definitions in an extra file (common.lua):
Code: Select all
return function ()
local common = {}
------------------------------------------------------------------------------------
-- Read startup settings
common.get_startup_settings= function()
local f_name = "common.get_startup_settings()"
if settings and settings.startup then
common.long_reach = settings.startup["GCKI-long_reach"].value
common.debug_in_log = settings.startup["GCKI-debug_in_log"].value
else
common.error("Startup settings are not available!", f_name)
end
end
[…]
return common
end
I can then access these functions/variables from other files:
Code: Select all
GCKI = require('common')
[…]
GCKI.get_startup_settings()
[…]