What’s the best way to define game-wide constants/enums that are accessible to all scripts?
For example, scripts attached to a map game object, a player game object and a hud game object might all need to know the map’s tile size. Using Lua in the past I’ve put definitions such as TILE_SIZE = 32 or NORTH = {0, 1} in a ‘constants.lua’ file and 'require’d that file in each script as needed. Is that a sensible way to do things in Defold?
( I realize there aren’t really such things as constants in Lua but I my own convention of defining them in uppercase has never caused a problem )
… provided the required file is in the root folder?
I had to specify the path ( C_ = require"/main/constants") as it seemed to make more sense to keep it alongside the other scripts in /main - might help someone else
No. All script component code is evaluated when the components are loaded at startup. Try placing a print() at top level and you’ll see. The location of the script file is irrelevant. All scripts are evaluated in the same Lua context (you can change that with the “Shared state” setting).