pass variable information between lua files/scenes

Hello 

I am making a game and am trying to implement a menu scene where the player selects the difficulty.  When the player selects the difficulty he gets moved onto the main game.  The only information I want the difficulty to pass to the main game is a time variable 60, 45 ,30 seconds etc. 

My question is how can I pass the information between the two lua files/scenes.

I have attached a simple picture to show what i mean.

Thanking You

You could use a global variable, but they’re rather nasty. Are you using storyboard to handle your scenes? If so, when you call gotoScene from the menu scene, add an options table:

local options = { effect = "crossFade", time = 500, params = { difficulty = "easy"} } storyboard.gotoScene("gameScene", options)

The effect and time fields are the ones you can pass in anyway. The “params” table can be used to pass custom data between scenes.

Then in the game scene’s CreateScene function you do this:

function scene:createScene( event ) local difficulty = event.params.difficulty --rest of level creation goes here end

This allows information to be passed directly from one scene to another :slight_smile:

Let me know if you’re not sure about any of that (and if you’re not using storyboard then I’m afraid I’m not sure how to do it).

For future reference, please do not post the same post twice.  It fragments the discussion and pollutes the forums.   Please continue this discussion here:

http://forums.coronalabs.com/topic/39602-pass-variable-information-between-lua-filesscenes/

You could use a global variable, but they’re rather nasty. Are you using storyboard to handle your scenes? If so, when you call gotoScene from the menu scene, add an options table:

local options = { effect = "crossFade", time = 500, params = { difficulty = "easy"} } storyboard.gotoScene("gameScene", options)

The effect and time fields are the ones you can pass in anyway. The “params” table can be used to pass custom data between scenes.

Then in the game scene’s CreateScene function you do this:

function scene:createScene( event ) local difficulty = event.params.difficulty --rest of level creation goes here end

This allows information to be passed directly from one scene to another :slight_smile:

Let me know if you’re not sure about any of that (and if you’re not using storyboard then I’m afraid I’m not sure how to do it).

For future reference, please do not post the same post twice.  It fragments the discussion and pollutes the forums.   Please continue this discussion here:

http://forums.coronalabs.com/topic/39602-pass-variable-information-between-lua-filesscenes/