Game Dev Help

Hey Corona Developers! I couldn’t get around this small issue I encountered and need a bit of help. I have a timerSource that makes moles pop out and the objective is to get through the waves of moles popping out on the screen by hitting them. However as soon as I press play the moles start popping out instantly, how can I delay the moles for seconds that i desire, then make the moles start popping out. Here is part of my coding, anything helps, thanks!

local function showmole() lastmole.isVisible = false     local randomHole = math.floor(math.random() \* 1) + 1        lastmole = moles[randomHole]     lastmole:setReferencePoint(display.BottomCenterReferencePoint)     lastmole.yScale = 0.1     lastmole.isVisible = true     transition.to(lastmole, { time=300, yScale=1 }) end function startTimer()  if wavemoles == waveTable[wave] then         wave = wave + 1 print(tostring(wave)) print(waveText.text) waveText.text = tostring(wave) print(waveText.text) waveText.text = tostring(wave) wavemoles = 0 timerSource = timer.performWithDelay(timeToNextWave, startTimer) return end timerSource = timer.performWithDelay(timeToNextmole, startTimer) showmole() wavemoles = wavemoles + 1  timeToNextmole = math.max(timeToNextmole - 30, 600)  end

I’m a newbie and could be wrong but something looks missing from your code in that your timers are within your function and i can’t see how that function is called. But i think the following may be helpful.

I think a simple solution would be a switch.

When you enter a room the lights are off - you have to turn the switch for the lights to go on - electricity is constantly going towards the light but because the switch is off nothing happens.

The same logic can be used here.

Surround your mole creation code  with a simple if else statement ( startMoles = true or false )

and the second part of this is using timer.performWithDelay to start a simple function which flicks the switch, thus allowing the moles to start appearing.

The logic should work but again your code does not show how your function is called -unless i’m missing something.

T.

Hi,

It looks like the guy above is correct, there’s nowhere where you’ve actually called those actions. Also, I’m not sure if I am missing something, but I can’t really see where you’ve specified what the value of the ‘TimeToNextWave’ variable is, and based on the code provided it also looks like the variable ‘TimeToNextMole’ is used before it is defined? I’m not sure if there are other bits of the code which you haven’t shown above, where these variables are first stated?

Without a bit more info i couldn’t really be of more help, but I think generally in principle you want to look into the use of functions and timers.

Yes, here are my functions:

local timeToNextWave = 3000 local currentmoles = 0 local molesHit = 0 local timerSource local timeToNextmole = 1000 local wave = 1 local waveText local waveTable = {3, 5, 5, 5,} local wavemoles = 0

the “timetonextwave” is the pause between each number of waves which are represented by “wavetable”. I have everything else figured out and works perfectly sorry about that lack of info. What I am asking is how to use the functions I already have but in this case have a “delay” before the game even starts. As soon as I tap “play” it instantly starts popping out the moles instead of delaying a couple of seconds then start popping out. if you need any more info let me know! thanks a lot guys!

I’m a newbie and could be wrong but something looks missing from your code in that your timers are within your function and i can’t see how that function is called. But i think the following may be helpful.

I think a simple solution would be a switch.

When you enter a room the lights are off - you have to turn the switch for the lights to go on - electricity is constantly going towards the light but because the switch is off nothing happens.

The same logic can be used here.

Surround your mole creation code  with a simple if else statement ( startMoles = true or false )

and the second part of this is using timer.performWithDelay to start a simple function which flicks the switch, thus allowing the moles to start appearing.

The logic should work but again your code does not show how your function is called -unless i’m missing something.

T.

Hi,

It looks like the guy above is correct, there’s nowhere where you’ve actually called those actions. Also, I’m not sure if I am missing something, but I can’t really see where you’ve specified what the value of the ‘TimeToNextWave’ variable is, and based on the code provided it also looks like the variable ‘TimeToNextMole’ is used before it is defined? I’m not sure if there are other bits of the code which you haven’t shown above, where these variables are first stated?

Without a bit more info i couldn’t really be of more help, but I think generally in principle you want to look into the use of functions and timers.

Yes, here are my functions:

local timeToNextWave = 3000 local currentmoles = 0 local molesHit = 0 local timerSource local timeToNextmole = 1000 local wave = 1 local waveText local waveTable = {3, 5, 5, 5,} local wavemoles = 0

the “timetonextwave” is the pause between each number of waves which are represented by “wavetable”. I have everything else figured out and works perfectly sorry about that lack of info. What I am asking is how to use the functions I already have but in this case have a “delay” before the game even starts. As soon as I tap “play” it instantly starts popping out the moles instead of delaying a couple of seconds then start popping out. if you need any more info let me know! thanks a lot guys!