order that love loads files
Posted: Fri Oct 13, 2017 2:23 pm
I am confused about how love loads.
I’m trying to use a global variable, “timesAllowed”. I tried initializing it in main.lua in two ways, neither of which seemed to work as I expected. That is, when I tried to use this variable in another file, I got an error that the variable has a nil value. Note: The program is well developed and was working fine till I tried to add this.
First, I tried putting “timesAllowed = 5” (without the quotes) as the first line in the love.load() function in main.lua. That didn’t work, so I tried putting it BEFORE the love.load() function, immediately after the require statements. This also didn’t work.
This caused me to wonder about the order that love loads things, so I tried a few experiments. The one that surprised me seemed to indicate that files other than main.lua were loaded before main.lua. In the first line of several files I put a print statement with the name of the file. Ex: print(“splash”) as the first line in splash.lua. I did this with the files data.lua, main.lua (print statement after the require statements), play.lua, splash.lua, and useLimit.lua.
When I ran the file I got the print results in the order below:
splash
play
data
useLimit
main
Why would main be run LAST? How can I create a global variable?
Thanks.
I’m trying to use a global variable, “timesAllowed”. I tried initializing it in main.lua in two ways, neither of which seemed to work as I expected. That is, when I tried to use this variable in another file, I got an error that the variable has a nil value. Note: The program is well developed and was working fine till I tried to add this.
First, I tried putting “timesAllowed = 5” (without the quotes) as the first line in the love.load() function in main.lua. That didn’t work, so I tried putting it BEFORE the love.load() function, immediately after the require statements. This also didn’t work.
This caused me to wonder about the order that love loads things, so I tried a few experiments. The one that surprised me seemed to indicate that files other than main.lua were loaded before main.lua. In the first line of several files I put a print statement with the name of the file. Ex: print(“splash”) as the first line in splash.lua. I did this with the files data.lua, main.lua (print statement after the require statements), play.lua, splash.lua, and useLimit.lua.
When I ran the file I got the print results in the order below:
splash
play
data
useLimit
main
Why would main be run LAST? How can I create a global variable?
Thanks.