Hi I am new to Lua and I just studied the “Ghosts vs. Monsters” sample game that Corona made. I have a question about passing a variable to another scene.
In the “Ghosts vs. Monsters” sample code, I suspect they use the “director:changeScene( “level1” )” to open another file. However, I would like to know if there is any way to pass a variable to another scene ?
should I use a global variable ?? how does global variable work in Lua?
My suggestion is using a module as a central global data. Then when you change your scene using director (or your own system) you read data from that module.
That’s an equally good suggestion and elabguy, if you are at the stage you are comfortable using that rather than a global variable then it’s certainly a nice clean way of doing things
@Peach
Hello Peach, i rarely posts on the forum before i become Corona subscriber. But now i guess i will lurk in the forum much more often [import]uid: 41267 topic_id: 10016 reply_id: 36573[/import]
inas, I just wanted to personally thank you for your suggestion on how to make the variables accessible (utilizing Director specifically) above. You resolved something I was wrestling with a couple hours yesterday. I owe you big! You rock.
HI there… i did exactly as you wrote, word by word, line by line
result:
Runtime error
/Applications/CoronaSDK/testgame/main.lua:2: attempt to index global ‘director’ (a nil value)
stack traceback:
[C]: ?
/Applications/CoronaSDK/testgame/main.lua:2: in main chunk
Runtime error: /Applications/CoronaSDK/testgame/main.lua:2: attempt to index global ‘director’ (a nil value)
stack traceback:
[C]: ?
/Applications/CoronaSDK/testgame/main.lua:2: in main chunk
to be true, i don’t get the whole SCENE Concept.
Once i tested with that director.lua it loaded another .lua but looked as he would mix my first lua with the second.
can’t i just load another scene… my old comes completely closed/destroyed and the one i call opens up fresh and new?
thx
chris
[import]uid: 4795 topic_id: 10016 reply_id: 49317[/import]