Time method

I have a project that I have to make the timer method change the speed with which it is called according to the score.

So, at the beginning of the file I have a local variable called timerDaCamadaDoMetodoMe = 60 (and start it) and inside my create I have a timer! Timer.performWithDelay (TimerDamedDonameName, CallDenameDememy, 0)

And what’s going on? I have another timer that keeps changing the punctuation and I put an if / else for when the punctuation reaches such a value change the speed with which the timer is called. I started it and it changes the value of the variable, but it does not change anything at the speed at which the timer is called. what do I do?

[lua]local timerDaChamadaDoMetodoDoInimigo = 60
pontuacao = “”

function scene:create(event)

enemy:createEnemy()

local groupScene = self.view

pontuacao = display.newText( “0”, display.contentWidth/2 + 140, 10 )
pontuacao:setFillColor( 1, 0, 0 )
groupScene:insert(pontuacao)

wall1 = display.newRect( display.contentWidth - 50, display.contentHeight - 100, 5, 50 )
wall1:setStrokeColor( 1, 1, 0, 1 )
wall1.name = “wall1”
–physics.setGravity(0,0)
physics.addBody( wall1, “dynamic” ,{friction = 1, bounce = 0} )
groupScene:insert(wall1)

– wall2 = display.newRect( display.contentWidth/2 - 110, display.contentHeight - 100, 5, 50 )
– wall2:setStrokeColor( 1, 1, 0, 1 )
– wall2.name = “wall2”
–physics.setGravity(0,0)
– physics.addBody( wall2, “dynamic” ,{friction = 1, bounce = 0} )
– groupScene:insert(wall2)

estrada1 = display.newImage(“estrada.png”)–a primeira estrada
estrada1.x = display.contentWidth/2
estrada1.y = 250
estrada1.speed = 5
groupScene:insert(estrada1)

estrada2 = display.newImage(“estrada.png”)–a segunda estrada a que fica atras da tela
estrada2.x = display.contentWidth/2
estrada2.y = - 409
estrada2.speed = 5
groupScene:insert(estrada2)

imageShip = display.newImage(“ship.png”)–imageShipm da nave
imageShip.x = display.contentWidth/2
imageShip.y = display.contentHeight - 100
imageShip.speed = 2
imageShip.name = “ship”
physics.setGravity(0,0)
physics.addBody( imageShip, “static” ,{friction = 1, bounce = 0} )
groupScene:insert(imageShip)
–////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
left = widget.newButton({width = display.contentWidth/2 + 42, height =650, x = display.contentWidth/2 - 100, y = display.contentHeight/2 + 40 , shape=“roundedRect”,fillColor = { default={ 0, 0, 0, 0.1 }, over={ 0, 0, 0, 0.1} }, onPress = MoverLeft} )
groupScene:insert(left)
–////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
right = widget.newButton({width = display.contentWidth/2 + 42, height =650, x = display.contentWidth/2 + 100, y = display.contentHeight/2 + 40 , shape=“roundedRect”,fillColor = { default={ 0, 0, 0, 0.1 }, over={ 0, 0, 0, 0.1 } }, onPress = MoverRight} )
groupScene:insert(right)
–////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ButtonFire = widget.newButton({label=“Fire”,width= 20,height =40, x = display.contentWidth/2 - 100, y = display.contentHeight/2 + 235, shape=“circle”, fillColor = { default={ 1, 0, 1, 1 }, over={ 0, 1, 1, 1} }, onPress = createLaser} )
–////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
right:addEventListener(“touch”,MoverRight) – chama a funcao que faz fazer a nave se movimentar
left:addEventListener(“touch”,MoverLeft) – chama a funcao que faz fazer a nave se movimentar
–////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
timer.performWithDelay( 80,scrollingRoadEstrada2 ,0 )
timer.performWithDelay( 80,scrollingRoadEstrada1 ,0 )
trm = timer.performWithDelay( timerDaChamadaDoMetodoDoInimigo,chamaMetodoDoEnemy ,0 ) – faz o inimigo se movimentar entre um determinado tempo
timerPontuacao = timer.performWithDelay(2000, mudarPontuacao,0)
–////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
imageShip:addEventListener(“collision”, onCollision) – verifica a colisao
wall1:addEventListener(“collision”, onCollision)
–wall2:addEventListener(“collision”, onCollision)
end

function startEnemy() – cria os inimigos depois do game over
enemy:createEnemy()
trm = timer.performWithDelay( 80,chamaMetodoDoEnemy ,0 )
end

function startGame() – inicializa o botao de tiro depois do game over

ButtonFire = widget.newButton({label=“Fire”,width= 20,height =40, x = display.contentWidth/2 - 100, y = display.contentHeight/2 + 200, shape=“circle”, fillColor = { default={ 1, 0, 1, 1 }, over={ 0, 1, 1, 1} }, onPress = createLaser} )

imageShip.x = display.contentWidth/2
imageShip.y = display.contentHeight - 100

pontuacao.text = “0”
end

function mudarPontuacao() – muda a pontuacao depois de um tempo pre-definido

pontuacao.text = pontuacao.text + 10

print(timerDaChamadaDoMetodoDoInimigo)

if pontuacao.text < “100” then
timerDaChamadaDoMetodoDoInimigo = 60
elseif pontuacao.text >= “100” and pontuacao.text < “200” then --altera a velocidade do inimigo de acordo com a pontuacao
timerDaChamadaDoMetodoDoInimigo = 50
elseif pontuacao.text >= “200” and pontuacao.text < "300"then
timerDaChamadaDoMetodoDoInimigo = 40
elseif pontuacao.text >= “300” and pontuacao.text < "400"then
timerDaChamadaDoMetodoDoInimigo = 30
elseif pontuacao.text >= “400” and pontuacao.text < "500"then
timerDaChamadaDoMetodoDoInimigo = 20
elseif pontuacao.text >= “500” then
timerDaChamadaDoMetodoDoInimigo = 10
end

end

–/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function chamaMetodoDoEnemy()-- chama os metodos dos inimigos

enemy:MoverEnemy()
enemy:MoverEnemy2()
enemy:MoverEnemy3()
enemy:MoverEnemy4()
enemy:scrollEnemy1()
enemy:scrollEnemy2()
enemy:scrollEnemy3()
enemy:scrollEnemy4()

end[/lua]

Surely when coding you are testing each line you add? When you find a line that breaks then that line is at fault.

Don’t write loads of code without testing - makes finding bugs so much simpler.

Just some wise words for you!

Surely when coding you are testing each line you add? When you find a line that breaks then that line is at fault.

Don’t write loads of code without testing - makes finding bugs so much simpler.

Just some wise words for you!