Nesting temptriggers

Post Reply
ahuman
Posts: 2
Joined: Mon Nov 08, 2010 6:03 pm

Nesting temptriggers

Post by ahuman »

Hello. I'm new to Lua and new to Mudlet, so this might be a stupid question. I'm trying to write a commodity price tracker for a space combat MUD I play. In order to read the prices, I have to navigate through two menus, both of which have the same prompt.

The problem is that this version works perfectly:
Code: [show] | [select all] lua
function prompt1(planet, room)
	if room ~= "Trading Center" then
		fg( "red" )
		echo( "Not in a trading center" )
		resetFormat()
		return
	end
	send("buy")
	ship_prompt_tr = tempTrigger(
		"[Type a line of input or `@abort' to abort the command.]",
		[[
			send("1")
			killTrigger(ship_prompt_tr)
		]])
end
While the trigger in this version never fires:
Code: [show] | [select all] lua
function prompt1(planet, room)
	if room ~= "Trading Center" then
		fg( "red" )
		echo( "Not in a trading center" )
		resetFormat()
		return
	end
	send("buy")
	ship_prompt_tr = tempTrigger(
		"[Type a line of input or `@abort' to abort the command.]",
		[[
			send("1")
			prompt2(]]..planet..[[)
			killTrigger(ship_prompt_tr)
		]])
end
It also returns the error "Lua syntax error:[Type a line of input or `@abort' to abort the command.]" in the console. Please help?
Attachments
commodity.xml
(1.96 KiB) Downloaded 357 times

Lucky24
Posts: 52
Joined: Sun Sep 12, 2010 1:50 am

Re: Nesting temptriggers

Post by Lucky24 »

My guess would be the multiple [[ ]] brackets and the carriage returns make the complier confused. When using tempTrigger() and tempTimer(), and I need to use more than one set of [[ ]], I either put all the lua in one line (with semicolons separating the statements), which works fine, or create a new function which I call inside the [[]], so that I can better debug the code, if it's longer than a few statements.

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Nesting temptriggers

Post by Heiko »

ship_prompt_tr = tempTrigger(
"[Type a line of input or \`@abort\' to abort the command.]",
[[
send("1")
prompt2(]]..planet..[[)
killTrigger(ship_prompt_tr)
]])

or use [[ ]] instead of " " for the pattern.
Also note that nesting [[ isn't supported by Lua.

You should use exact match type of temp triggers or regex temp trigs instead of substring temp trigs in your case.

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

Re: Nesting temptriggers

Post by Vadi »

Nesting [[ is supported by Lua; you simply add another = in the middle for each level:

Literal strings can also be defined using a long format enclosed by long brackets. We define an opening long bracket of level n as an opening square bracket followed by n equal signs followed by another opening square bracket. So, an opening long bracket of level 0 is written as [[, an opening long bracket of level 1 is written as [=[, and so on. A closing long bracket is defined similarly; for instance, a closing long bracket of level 4 is written as ]====]. A long string starts with an opening long bracket of any level and ends at the first closing long bracket of the same level. Literals in this bracketed form can run for several lines, do not interpret any escape sequences, and ignore long brackets of any other level. They can contain anything except a closing bracket of the proper level.

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Nesting temptriggers

Post by Heiko »

Well, nesting [[ clearly is *not* supported by Lua. The ]=========] concept is simply a nasty workaround. Even worse is that nesting paragraph comments isn't possible either i.e. --[[ some comment --[[ some other comment ]]-- ]]-- isn't supported. This is imho the only really annoying limitation of the Lua parser and I hope that this will get improved in future versions.

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

Re: Nesting temptriggers

Post by tsuujin »

Heiko wrote:Well, nesting [[ clearly is *not* supported by Lua. The ]=========] concept is simply a nasty workaround. Even worse is that nesting paragraph comments isn't possible either i.e. --[[ some comment --[[ some other comment ]]-- ]]-- isn't supported. This is imho the only really annoying limitation of the Lua parser and I hope that this will get improved in future versions.
Workaround vs language feature is needless and overly confusing information to the Lua novice. Suffice to say it works but isn't recommended.

Post Reply