Passing Data Between Scenes

Is there any way to pass data between scenes without using a global variable? Suppose you set a bunch of options in an options scene, and then you want to load up the game with those options in a separate scene? How is information shared between scenes? Do we place each scene in its own lua file with its own new function and have each new function look for global variable data?

Is there a way to pass in data to a scene? Seems like if a scene isn’t active, its out of memory, and if a scene is activated, its rebuilt completely from new() (which takes no params). So it needs to rebuild itself each time the scene is changed from global data. [import]uid: 38858 topic_id: 7415 reply_id: 307415[/import]

I would like to know also.

I actually need to carry over only one variable so I (thought) I made it a global variable since the Docs say global variables last for the duration of the Application.

I added this on screen1:
globalForce = 5

I added this on screen2:
print (globalForce)

and I get an error that it is nil

Am I doing something wrong? The Docs seem to say that just not using the word local would make the variable global but it isn’t coming through that way. [import]uid: 22392 topic_id: 7415 reply_id: 26337[/import]

On screen2 change:

print (globalForce)

to:

print (screen1.globalForce)

  • Steven [import]uid: 7175 topic_id: 7415 reply_id: 26736[/import]

Great, that worked.
Thanks! [import]uid: 22392 topic_id: 7415 reply_id: 26783[/import]

Awesome, I just ran into the same issue. Makes sense now :slight_smile: [import]uid: 13604 topic_id: 7415 reply_id: 27962[/import]