Question about tempTimer

Post Reply
AncientTree
Posts: 2
Joined: Tue Jun 13, 2023 9:47 pm

Question about tempTimer

Post by AncientTree »

Hello, I have a question about the tempTimer function, is it not possible to have something like below? It looks like it accepts variables but not anything with an assignment (= sign)

local t = 0
tempTimer(t=t+1, [[ send("Hello World") ]])

Does it mean i will have to do the calculations outside and then put the variable in like this?

local t = 0
t=t+1
tempTimer(t, [[ send("Hello World") ]])

Also is there a way to cancel all of the temptimers?

Thanks!

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: Question about tempTimer

Post by demonnic »

the expression "t=t+1" doesn't return t inherently, it returns nil, so you do need to do the calculations outside of the function invocation.

There is no built in way but the following function will do it
Code: [show] | [select all] lua
function killAllTempTimers()
  local topIndex = tempTimer(0, function() end)
  for i = 1, topIndex do
    killTimer(i)
  end
end

AncientTree
Posts: 2
Joined: Tue Jun 13, 2023 9:47 pm

Re: Question about tempTimer

Post by AncientTree »

Understood, thanks!

Post Reply