Page 1 of 1
GAG next
Posted: Mon Jun 21, 2010 4:01 pm
by lex
Hi,
I would like to create function, which will gag next line based on pattern and than disable itself.
So far I have following
function gagNext(regexPattern)
local ID = tempRegexTrigger(
regexPattern,
[[deleteLine() killTrigger(ID)]]
)
end
This is not working, because ID variable is not global. (And I don't want to make it global, because I would like to have multiple gagNext(...) calls add same time. Is there any way around it e.g. put value of ID into callback string?
I would like to use it like:
gagNext("line1 to gag")
gagNext("line2 to gag")
Thank you
Re: GAG next
Posted: Mon Jun 21, 2010 4:04 pm
by tsuujin
you create a trigger that precedes the line you want to gag, and use that trigger to create a tempLineTrigger which gags one line past.
Re: GAG next
Posted: Mon Jun 21, 2010 4:42 pm
by lex
Thanks for quick reply, but this will not help me. I still need to disable original trigger somehow.
Let me rephrase what I would like to archive:
- function that will look gag line base on param
- it will only gag first line fulfilling pattern and then it will disable itself
- you should be able to have multiple of 'gagNext' triggers at same time
Look at following code, which will do job only for ONE trigger at the time:
gag.trig1_id = nil
function gagTrig1()
gag.trig1_id = tempRegexTrigger(
"^You will no longer see prompts\.$",
[[deleteLine() killTrigger(gag.trig1_id)]]
)
end
Re: GAG next
Posted: Mon Jun 21, 2010 4:44 pm
by tsuujin
lex wrote:Thanks for quick reply, but this will not help me. I still need to disable original trigger somehow.
Let me rephrase what I would like to archive:
- function that will look gag line base on param
- it will only gag first line fulfilling pattern and then it will disable itself
- you should be able to have multiple of 'gagNext' triggers at same time
Look at following code, which will do job only for ONE trigger at the time:
gag.trig1_id = nil
function gagTrig1()
gag.trig1_id = tempRegexTrigger(
"^You will no longer see prompts\.$",
[[deleteLine() killTrigger(gag.trig1_id)]]
)
end
Ok. Create a table to hold the tempTriggers. Your function creates the trigger, which on triggering deletes itself and creates a temp line trigger to gag whatever number of lines after that one you want. You can have as many as you want this way.
Re: GAG next
Posted: Mon Jun 21, 2010 5:43 pm
by lex
Thanks for another idea, but... well main issue was with passing real ID (or something) to trigger callback string. I did solve it with another function (_gagNextBuildString) that just creates and returns string.
Working script is bellow!
-----------------------------------------------------------------------------
-- gagNext() will create trigger to gag first matching line
--
-- for example
-- gagNext("gag this line")
-- gagNext("and this one as well")
--
_gag = _gag or {}
function _gagNextBuildString(key)
local out = [[deleteLine() killTrigger(_gag["]]..key..[["]) _gag["]]..key..[["]=nil]]
return out
end
function utils.gagNext(regexPattern)
if not _gag[regexPattern] then
local id = tempRegexTrigger(
regexPattern,
_gagNextBuildString(regexPattern)
)
_gag[regexPattern] = id
end
end