I'm wondering if there is any way to pass a local table value into a trigger/timer, and have it come out on the other side able to use it. I want to be able to pass in the local "self" table, so I can use it within the temp trigger and or timer.
So, someway to pass a local table value into the tempRegexTrigger() like so:
local myTable = {"stuff"}
tempRegexTrigger("hello world",[[triggerStuff=myTable]])
So I'd want triggerStuff = {"stuff"}, whereas it would simply throw an error as written above.
And yes, I'm aware I could just use a global variable. But I'm trying to avoid that.
EDIT: I tried the following with no success:
Doens't work because you can't concatenate a table value
tempRegexTrigger("hello world",[[triggerStuff=]]..myTable)
I'm asking because I'm writing an object to handle success/fail triggers and timeout commands, and I want to refer back to the calling object/function from within a temp trigger and or timer. Of course, when the trigger is fired, the 'self' table doesn't work, I assume because the trigger code is not being executed from within the original function where 'self' is defined. So when you do something like tempRegexTrigger("hello world",[[self:Start(lua)]]) it doesn't know what 'self' is.
Thus, An actual example of what I'm trying to accomplish (heavily simplified) is as follows:
commandWaterfall = commandWaterfall or {}
commandWaterfall.triggers = commandWaterfall.triggers or {}
commandWaterfall.timers = commandWaterfall.timers or {}
-- just make an inheritable object in lua
function commandWaterfall(o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end
-- kill the trigger+timer when either completes
function commandWaterfall:Complete(event,lua)
if event == "success" then
if self.triggers.triggerID then
killTrigger(self.triggers.triggerID)
self.triggers.triggerID = nil
end
if self.timers.timerID then
killTimer(self.triggers.timerID)
self.timers.timerID = nil
end
end
if event == "timeout" then
if self.triggers.triggerID then
killTrigger(self.triggers.triggerID)
self.triggers.triggerID = nil
end
if self.timers.timerID then
self.timers.timerID = nil
end
end
return lua
end
-- start the command waterfall
function commandWaterfall:Start(command,successTrigger,successLua,failTrigger,failLua,timeout,timeoutLua)
self.triggers.successTriggerID = tempRegexTriggger(trigger,[[commandWaterfall.Complete(]]..self..[[,"success",lua)]])
self.triggers.failTriggerID = tempRegexTriggger(trigger,[[commandWaterfall.Complete(]]..self..[[,"fail",lua)]])
self.timers.timerID = tempTimer(timeout,[[commandWaterfall.Complete(]]..self..[[,"timeout",lua]])
expandAlias(command)
end
-- create a new object
eatFood = commandWaterfall:New()
-- start the eatFood command
eatFood:Start("eat food","^You eat some food$",[[send("Yummy!")]],"^You must take the food out of your backpack first$",[[send("get food from my backback");send("eat food")]],5,[[cantEatFood()]])
I had this working without making it into an object, but the inheritable object is nice as you can keep track of the states easily, and have multiple success/fail triggers. I also added a "max retries". It's just simpler within an object than keeping track of all the values in a big list. I suppose I could cheat the inheritance and just call waterfall:Complete() instead of self:Complete(), but that kind of defeats the purpose.