[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  AddTrigger/Ex function with Regexp and \n
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

AddTrigger/Ex function with Regexp and \n

It is now over 60 days since the last post. This thread is closed.   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Dontarion   USA  (62 posts)  [Biography] bio
Date Tue 08 Jun 2010 11:43 PM (UTC)  quote  ]
Message
StringRoomListCur = CurrentRoom .. ". (" .. CurrentArea .. ")$\n^" .. CurrentDesc
StringRoomListOld = OldRoom .. ". (" .. OldArea .. ")$\n^" .. OldDesc
-- These rooms look like: The gates of Mhaldor. (Mhaldor)\nRoomDescription.
StringRoomListCur = string.gsub (StringRoomListCur, "[^%a%c%d]", "\\" .. "%1")
StringRoomListOld = string.gsub (StringRoomListOld, "[^%a%c%d]", "\\" .. "%1")
AddTriggerEx("", StringRoomListCur, "[WORMHOLE: " .. OldArea .. ", " .. OldRoom .. "]", 41, -1, 0, "", "", 2, 100)
AddTriggerEx("", StringRoomListOld, "[WORMHOLE: " .. CurrentArea .. ", " .. CurrentRoom .. "]", 41, -1, 0, "", "", 2, 100)

That is the code inside an alias called whm. It creates two triggers based on information stored about the previous two rooms visited (wormholes in Achaea). My only problem I keep running into is \n, \\n, to \\\\\n doesn't work. Am I missing something here because the system keeps coming back with the string is incomplete at the \n as the alias keeps putting in a literal line return mid string.

Compile error
World: Achaea
Immediate execution
[string "Alias: "]:3: unfinished string near '")'
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #1 on Wed 09 Jun 2010 12:29 AM (UTC)  quote  ]

Amended on Wed 09 Jun 2010 12:47 AM (UTC) by Twisol

Message
<ignore this post>

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Dontarion   USA  (62 posts)  [Biography] bio
Date Reply #2 on Wed 09 Jun 2010 12:33 AM (UTC)  quote  ]
Message
Well, I don't want it to print out the \n. I want it to make the trigger line with \n in it. What ends up happening is when I do AddTrigger/Ex it turns the \\n into a real newline and messes up the string so the AddTrigger fails.
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #3 on Wed 09 Jun 2010 12:38 AM (UTC)  quote  ]

Amended on Wed 09 Jun 2010 12:48 AM (UTC) by Twisol

Message
Try using $ in the trigger pattern instead of \n. You won't have to go through all these pains.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (19,631 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Wed 09 Jun 2010 01:36 AM (UTC)  quote  ]
Message
Dontarion said:

Well, I don't want it to print out the \n. I want it to make the trigger line with \n in it. What ends up happening is when I do AddTrigger/Ex it turns the \n into a real newline and messes up the string so the AddTrigger fails.


If you do "send to script" (rather than calling a script function in a script file) MUSHclient preprocesses \n as a newline (before sending to the script engine), thus you get complaints about unterminated strings. To get the \ appear inside the script itself, you need to double it (ie. \\n).

You can avoid some of this confusion by not scripting inside the trigger (or alias) but using a script file, and just putting the function name in the Script box. Alternatively, use the Lua string constants that let you imbed newlines like this:


s = [[This string will
have a newline inside it]]


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Dontarion   USA  (62 posts)  [Biography] bio
Date Reply #5 on Wed 09 Jun 2010 02:12 PM (UTC)  quote  ]

Amended on Wed 09 Jun 2010 04:05 PM (UTC) by Dontarion

Message

function createWormholeTrigger ()
	if CurrentRoom == "" or OldRoom == "" then
		Note("")
		Note("You need to collect both sides of the wormhole to create the triggers.")
		Note("")
	else
		CurrentRoomHold = CurrentRoom
		OldRoomHold = OldRoom
		CurrentRoom = string.gsub (CurrentRoom, "[^A-Za-z0-9 ]", "\%1")
		OldRoom = string.gsub (OldRoom, "[^A-Za-z0-9 ]", "\%1")
		CurrentArea = string.gsub (CurrentArea, "[^A-Za-z0-9 ]", "\%1")
		OldArea = string.gsub (OldArea, "[^A-Za-z0-9 ]", "\%1")
		CurrentDesc = string.gsub (CurrentDesc, "[^A-Za-z0-9 ]", "\%1")
		OldDesc = string.gsub (OldDesc, "[^A-Za-z0-9 ]", "\%1")
		StringRoomListCur = CurrentRoom .. "\. \(" .. CurrentArea .. "\)\n" .. CurrentDesc
		StringRoomListOld = OldRoom .. "\. \(" .. OldArea .. "\)\n" .. OldDesc
		--Note(StringRoomListCur)
		--Note(StringRoomListOld)
		if IsTrigger(string.gsub (CurrentRoomHold, "[^A-Za-z0-9]", "_")) then
			AddTriggerEx(string.gsub (CurrentRoomHold, "[^A-Za-z0-9]", "_"), StringRoomListCur, "[WORMHOLE\: " .. OldArea .. "\, " .. OldRoom .. "]", 41, -1, 0, "", "", 2, 100)
			SetTriggerOption(string.gsub (CurrentRoomHold, "[^A-Za-z0-9]", "_"), "multi_line", "1")
			SetTriggerOption(string.gsub (CurrentRoomHold, "[^A-Za-z0-9]", "_"), "lines_to_match", "2")
			SetTriggerOption(string.gsub (CurrentRoomHold, "[^A-Za-z0-9]", "_"), "group", "AAAA")
			--When really IsTrigger it shows up at 0.
		else
			-- here would be a trigger setup for ones with the same name to start adding numbers
			-- on the end of it.
		end
		
		if IsTrigger(string.gsub (OldRoomHold, "[^A-Za-z0-9]", "_")) then
			AddTriggerEx(string.gsub (OldRoomHold, "[^A-Za-z0-9]", "_"), StringRoomListOld, "[WORMHOLE\: " .. CurrentArea .. "\, " .. CurrentRoom .. "]", 41, -1, 0, "", "", 2, 100)
			SetTriggerOption(string.gsub (OldRoomHold, "[^A-Za-z0-9]", "_"), "multi_line", "1")
			SetTriggerOption(string.gsub (OldRoomHold, "[^A-Za-z0-9]", "_"), "lines_to_match", "2")
			SetTriggerOption(string.gsub (OldRoomHold, "[^A-Za-z0-9]", "_"), "group", "AAAA")
		else
			-- Here would be if there is already a trigger with the same name to start adding numbers
			-- on the end of it.
		end
	end
end


I decided to go with the script file because it's just easier. I edit now because I saw the option out of the corner of my eye flipping between windows.

Can't seem to make it work on areas that have spaces in their names. Working on that problem now. -- Figured out the issue - you can't have trigger names with - in it. The new code turns anything non-alphanumeric into _'s.
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


2,344 views.

It is now over 60 days since the last post. This thread is closed.   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Web site powered by FutureQuest.Net]