How to make a tempTimer fire

Post Reply
Slayd
Posts: 102
Joined: Mon Jul 25, 2011 4:57 am

How to make a tempTimer fire

Post by Slayd »

I want a flag I use, AntiTheftFlag, to reset to true after 2 seconds.

Here is the function that creates the timer and enables it:
Code: [show] | [select all] lua
function reset_AntiTheftFlag()
  local tt = tempTimer(2.0, [[function () AntiTheftFlag = true end]])
  enableTimer(tt)
end
The timer never fires. I can see it when I search

I tried
Code: [show] | [select all] lua
enableTimer(tostring(tt))
as I saw a string used in one place in the documentation. That didn't work either.

What is it I need to do to make this work?

User avatar
Belgarath
Posts: 232
Joined: Fri Jul 26, 2013 7:19 am
Discord: macjabeth#7149

Re: How to make a tempTimer fire

Post by Belgarath »

You're creating an anonymous function inside double brackets, but it isn't being called. You'd have to take the double brackets off. The way you're doing the timer is a bit strange, as local variables can't be called in the global space >.> This is the standard method:
Code: [show] | [select all] lua
function reset_antitheftflag ()
  if antitheftTimer then killTimer(antitheftTimer) end
  antitheftTimer = tempTimer(2, [[antitheftflag = true]])
end

Slayd
Posts: 102
Joined: Mon Jul 25, 2011 4:57 am

Re: How to make a tempTimer fire

Post by Slayd »

good man. thanks!

Post Reply