Page 1 of 1

Question about tempTimer

Posted: Tue Jun 13, 2023 10:12 pm
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!

Re: Question about tempTimer

Posted: Wed Jun 14, 2023 2:18 am
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

Re: Question about tempTimer

Posted: Wed Jun 14, 2023 2:48 am
by AncientTree
Understood, thanks!