GAG next

Post Reply
lex
Posts: 55
Joined: Fri May 14, 2010 2:28 pm

GAG next

Post 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
Code: [show] | [select all] lua
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:
Code: [show] | [select all] lua
gagNext("line1 to gag")
gagNext("line2 to gag")
Thank you

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: GAG next

Post 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.

lex
Posts: 55
Joined: Fri May 14, 2010 2:28 pm

Re: GAG next

Post 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:
Code: [show] | [select all] lua
gag.trig1_id = nil

function gagTrig1()
	gag.trig1_id = tempRegexTrigger(
		"^You will no longer see prompts\.$", 
		[[deleteLine() killTrigger(gag.trig1_id)]]
	)
end

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: GAG next

Post 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:
Code: [show] | [select all] lua
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.

lex
Posts: 55
Joined: Fri May 14, 2010 2:28 pm

Re: GAG next

Post 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!
Code: [show] | [select all] lua
-----------------------------------------------------------------------------
-- 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

Post Reply