why is this not working (timers)

if testDps == nil then  
 testDps = timer.performWithDelay( 1000, testDmg, 0 )  
 testTimer = timer.performWithDelay( 4000, killTest, 1 )  
 if testDps == nil then  
 print( "wtf" )  
 testDps = timer.performWithDelay( 1000, testDmg, 0 )  
 end  
end  

the first time I run it, it works. it creates the testDps fine. but after 4 seconds when it kills it, and i retry. it doesnt create it anymore even through the double if testDps == nil . the kill function all is the following:

timer.cancel( testDps )  
testDps = nil  

what am i missing? thanks in advance [import]uid: 77199 topic_id: 32857 reply_id: 332857[/import]

it’s because the code only runs once from top to bottom, so in that sense the app doesn’t ever go inside your 2nd IF statement since testDps was just assigned. [import]uid: 144908 topic_id: 32857 reply_id: 130584[/import]

it’s because the code only runs once from top to bottom, so in that sense the app doesn’t ever go inside your 2nd IF statement since testDps was just assigned. [import]uid: 144908 topic_id: 32857 reply_id: 130584[/import]

Sorry I should have fully explained the situation. My whole point is that it IS going through the second if, even though it never should. That’s why I had the print there as a test, to see if it actually goes through, and it does, even though it shouldn’t.

testDps is created the first time and it works, but once it gets timer.cancel and set to nil, it will never work again. For some reason it’s not recreating the timer, not even with 2 if’s. Which doesn’t make sense to me at all since I’ve used this method once before and that one works just fine. [import]uid: 77199 topic_id: 32857 reply_id: 130589[/import]

Sorry I should have fully explained the situation. My whole point is that it IS going through the second if, even though it never should. That’s why I had the print there as a test, to see if it actually goes through, and it does, even though it shouldn’t.

testDps is created the first time and it works, but once it gets timer.cancel and set to nil, it will never work again. For some reason it’s not recreating the timer, not even with 2 if’s. Which doesn’t make sense to me at all since I’ve used this method once before and that one works just fine. [import]uid: 77199 topic_id: 32857 reply_id: 130589[/import]

It goes through the 2nd IF statement? Hmm… maybe the testDps variable is being accessed somewhere else, try localizing that variable to just this function then check if it still prints ‘wtf’. [import]uid: 144908 topic_id: 32857 reply_id: 130650[/import]

Hi there,

Out of curiosity, why in the line [lua]testDps = timer.performWithDelay( 1000, testDmg, 0 )[/lua] do you set the iterations parameter to 0? This will cause the timer will continue executing indefinitely every 1000 milliseconds. From what I can see of the code you posted so far, I don’t think that would explain your issue, but I wanted to point it out anyway.

I’d also be interested to know how the code you posted is triggered (you mentioned it works the first time you trigger it, but not subsequent times).

Last, is testDps a global variable?

It would help if you could post a complete, but minimal, main.lua file that exhibits the issue.

  • Andrew [import]uid: 109711 topic_id: 32857 reply_id: 130657[/import]

It goes through the 2nd IF statement? Hmm… maybe the testDps variable is being accessed somewhere else, try localizing that variable to just this function then check if it still prints ‘wtf’. [import]uid: 144908 topic_id: 32857 reply_id: 130650[/import]

Hi there,

Out of curiosity, why in the line [lua]testDps = timer.performWithDelay( 1000, testDmg, 0 )[/lua] do you set the iterations parameter to 0? This will cause the timer will continue executing indefinitely every 1000 milliseconds. From what I can see of the code you posted so far, I don’t think that would explain your issue, but I wanted to point it out anyway.

I’d also be interested to know how the code you posted is triggered (you mentioned it works the first time you trigger it, but not subsequent times).

Last, is testDps a global variable?

It would help if you could post a complete, but minimal, main.lua file that exhibits the issue.

  • Andrew [import]uid: 109711 topic_id: 32857 reply_id: 130657[/import]