Sharing variables across modules

Hi all. Long time lurker, first time poster. Just want to thank everyone for being so helpful already without me even having to ask a question.

Onto my question. I’m working on a game that uses a timer on each level and I’m currently using a module to load the generic timer into each level. However, I want to be able to change the length of the timer based upon the current level. For example, level one = 30 secs, level two = 45 secs, etc.

Is there a way to change the timer length variable in the timer module based on the current game level? Or is there a better practice I should be following to do the same thing? I’m sure it easier than I’m making it on myself, but could use the help. Thanks all! [import]uid: 43083 topic_id: 17937 reply_id: 317937[/import]

create your needed variables as global, like that:
_G.somevar = “i am global varible :)” [import]uid: 16142 topic_id: 17937 reply_id: 68481[/import]

Could you not create a local variable that stores the time limit for that particular level and then pass that variable as a parameter to your timer module? It depends how your timer module is set up. Something like…
[lua]-- Import timerModule

local timerModule = require “timerModule”
– Set time limit for this level

local timeLimit = 30
– Get new timer from timerModule

local countdown = timerModule.newCountdown(timeLimit)

…[/lua]
This way, you’re keeping everything local too. [import]uid: 74503 topic_id: 17937 reply_id: 68494[/import]

If you’re using the Storyboard API for scene management, this is achieved very easily (and doesn’t involve the use of any globals).

Here’s a link to the FAQ question for Storyboard:
http://blog.anscamobile.com/2011/11/common-storyboard-api-questions/#how-do-you-transfer-data-variables-between-scenes [import]uid: 52430 topic_id: 17937 reply_id: 68510[/import]

Thanks for the suggestions guys. I had an idea parameters could be used for this, so good way to force me to practice with them more.

And definitely liking what I’m seeing in with storyboard and this is another reason to look at it closer. Thanks all! [import]uid: 43083 topic_id: 17937 reply_id: 68781[/import]