Timer Delay

Ok real noob question,but im very new and dont understand yet. But heres my problem…Im trying to write a delay to change the screen after hitting the button,reason for this is i want to add some goodies after you choose your answer and not be wisked away to the next question instantly…heres my code involving this it has no errors in simulator command line window,but never the less it does not delay at all…as if this isnt added …

local function pick1( event )
print( “pick1 called” )
end

local function pick1 (event)
if event.phase == “ended” then
audio.stop(gameeffect3)
score.setScore( score.getScore() + 0)
timer.performWithDelay(9000, director:changeScene (“q2”))
end
end
answer1:addEventListener(“touch”, pick1)

Thank You in advance for your help [import]uid: 124254 topic_id: 23044 reply_id: 323044[/import]

Hello

Your delayed call should be something like this:

timer.performWithDelay(9000, function() director:changeScene ("q2") end)  

or

local goToSceneQ2 = function()  
 director:changeScene ("q2")  
end  
timer.performWithDelay(9000, goToSceneQ2)  

both will give the same result

Hope this helps

Raúl Beltrán
MIU Games [import]uid: 44101 topic_id: 23044 reply_id: 92140[/import]

Success,thank you very much Raúl Beltrán,i used the first one it looked easier to plug into the script…works great…didnt realize needed to (double call)function to make this happen,but its working as expected…now i have plenty of time in this function to make kool sounds and stuff before changing the screen now…\o/…anyone looking to do this look no further this thread is for YOU…

UPDATE… It seems that i was a bit hasty,this only works on the FIRST answer button,i made it exact for all,but it only works on the first one…here look

local function pick1 (event)
if event.phase == “ended” then
audio.stop(gameeffect3)
score.setScore( score.getScore() + 0)
timer.performWithDelay(9000, function() director:changeScene (“q2”) end)
end
end
answer1:addEventListener(“touch”, pick1)

local function pick2 (event)
if event.phase == “ended” then
audio.stop(gameeffect3)
score.setScore( score.getScore() + 0)
timer.performWithDelay(9000, function() director:changeScene (“q2”) end)
director:changeScene (“q2”)
end
end
answer2:addEventListener(“touch”, pick2)

local function pick3 (event)
if event.phase == “ended” then
audio.stop(gameeffect3)
score.setScore( score.getScore() + 5)
timer.performWithDelay(9000, function() director:changeScene (“q2”) end)
director:changeScene (“q2”)
end
end
answer3:addEventListener(“touch”, pick3) [import]uid: 124254 topic_id: 23044 reply_id: 92213[/import]

any ideas guys?..i have tried to comment out the first to see it it will work further down…no … :frowning: …it seems even if commented it only functions on the first of the 3 answers [import]uid: 124254 topic_id: 23044 reply_id: 92336[/import]

Hi again

your functions pick2 and pick3 are calling director:changeScene (“q2”) twice: one with delay and the second call fires immediatly, I guess your code should look like

local function pick2 (event)  
 if event.phase == "ended" then  
 audio.stop(gameeffect3)  
 score.setScore( score.getScore() + 0)  
 timer.performWithDelay(9000, function() director:changeScene ("q2") end)  
 end  
end  
answer2:addEventListener("touch", pick2)  
  
local function pick3 (event)  
 if event.phase == "ended" then  
 audio.stop(gameeffect3)  
 score.setScore( score.getScore() + 5)  
 timer.performWithDelay(9000, function() director:changeScene ("q2") end)  
 end  
end  

Cheers

Raúl Beltrán
MIU Games [import]uid: 44101 topic_id: 23044 reply_id: 92359[/import]

I have no idea what that means.Im looking at the code and cant see what u changed other than placement of rows…Im a total noob.Maybe I should try to find a class so i can learn basics of coding …Btw Grandmaster Obe-Wan…It works perfectly…I am in your debt…thank you very much sir…If i can ever be of service feel free to ask… : )

CODERS UNITE AGAINST LUA ILLITERACY…LOL
[import]uid: 124254 topic_id: 23044 reply_id: 92366[/import]