tempTimers and using a function

Post Reply
Dyron
Posts: 14
Joined: Thu Jul 28, 2016 5:02 pm

tempTimers and using a function

Post by Dyron »

I am attempting to use temptimers with a function..

I'd like to make the temptimer do something like this...
Code: [show] | [select all] lua
function remcolor()
  if table.contains(colors, item) then
    table.remove(colors, table.index_of(colors, item))
    echo("I've removed the " .. item .. " color.")
  end
end 

--Below is based off of a trigger
local item = "Brown"
tempTimer(2, remcolor(item))
I just can't figure out how to use the function inside the temptimer.

User avatar
SlySven
Posts: 1019
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: tempTimers and using a function

Post by SlySven »

I'd save/include the function in a "Script" item, then call:
Code: [show] | [select all] lua
tempTimer(2, remcolor("Brown"))
as needed from your own lua code, but that is just my 2 pence worth and may not be right... ;)

Dyron
Posts: 14
Joined: Thu Jul 28, 2016 5:02 pm

Re: tempTimers and using a function

Post by Dyron »

remcolor() is a script function

Trigger:
You are removing the brown from your aura.

I'd do:
You are removing the (\w+) from your aura\.
Code: [show] | [select all] lua
--Code for the trigger
tempTimer(2, remcolor(matches[2]))
So after 2 seconds.. I want it to run that script(remcolor) and match it to the color that was in the trigger.

Dyron
Posts: 14
Joined: Thu Jul 28, 2016 5:02 pm

Re: tempTimers and using a function

Post by Dyron »

Anyone else have an idea how to make this work?

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: tempTimers and using a function

Post by Vadi »

Yep, use:
Code: [show] | [select all] lua
  tempTimer(2, function() remcolor(matches[2]) end)
The function() [...] end will capture your matches[2] in a closure so it's still available after 2s and it'll also ensure your function is called then, not right when you create the tempTimer.

Dyron
Posts: 14
Joined: Thu Jul 28, 2016 5:02 pm

Re: tempTimers and using a function

Post by Dyron »

Outstanding, thank you, Vadi!

Post Reply