Page 1 of 2

Replacing a String

Posted: Sun Jan 30, 2011 10:41 am
by Theiwar
I'm attempting to replace the string:

Standing the Aeon on your open palm, you blow it lightly at Bob and watch as it seems to slow his movement through the time stream.

with the following text to be highlighted:

++++++++AEON LANDED++++++++

Here is my code, what am I doing wrong?

Trigger
Code: [show] | [select all] lua
^Standing the Aeon on your open palm, you blow it lightly at (\w+) and watch as it seems to slow (\w+) movement through the time stream.$
Script
Code: [show] | [select all] lua
replace("+++++++++++++++++++++++++ AEON LANDED  ++++++++++++++++++++++++")
setFgColor(255,0,0)
setBgColor(255,255,255)
resetFormat()

Re: Replacing a String

Posted: Sun Jan 30, 2011 12:14 pm
by Heiko
You haven't selected anything -> replace() does nothing. There are several select functions -> api docs

Re: Replacing a String

Posted: Sun Jan 30, 2011 1:09 pm
by Theiwar
Ahhh sorry missed the top line of my script.
Code: [show] | [select all] lua
selectString("Standing the Aeon on your open palm, you blow it lightly at " ..matches[2].. " and watch as it seems to slow " ..matches[3].. " movement through the time stream.")
replace("+++++++++++++++++++++++++ AEON LANDED  ++++++++++++++++++++++++")
setFgColor(255,0,0)
setBgColor(255,255,255)
resetFormat()

Re: Replacing a String

Posted: Sun Jan 30, 2011 1:13 pm
by Heiko
You have forgotten the second argument of selectString() -> syntax error

You should simply use matches[1] here which means the entire match and selectCaptureGroup()

Re: Replacing a String

Posted: Sun Jan 30, 2011 1:42 pm
by Vadi
Just use selectString(line, 1)

Re: Replacing a String

Posted: Sun Jan 30, 2011 1:51 pm
by Theiwar
Ok so I used SelectCaptureGroup(0) assuming that using 0 would be the equivalent of matches[1]. Still no luck though.
Code: [show] | [select all] lua
selectCaptureGroup(0)
replace("+++++++++++++++++++++++++ AEON LANDED  ++++++++++++++++++++++++")
setFgColor(255,0,0)
setBgColor(255,255,255)
resetFormat()

Re: Replacing a String

Posted: Sun Jan 30, 2011 2:38 pm
by Vadi
No, you'd want selectCaptureGroup(1)

Re: Replacing a String

Posted: Sun Jan 30, 2011 4:48 pm
by Theiwar
Ok still not working, however when I use the feedTriggers function to test it works great:
Code: [show] | [select all] lua
feedTriggers("\nStanding the Aeon on your open palm, you blow it lightly at Bob and watch as it seems to slow his movement through the time stream.\n")
Here is the trigger RegEx:
Code: [show] | [select all] lua
^Standing the Aeon on your open palm, you blow it lightly at (\w+) and watch as it seems to slow (\w+) movement through the time stream.$
and code:
Code: [show] | [select all] lua
selectCaptureGroup(1)
replace("+++++++++++++++++++++++++ AEON LANDED  ++++++++++++++++++++++++")
setFgColor(255,0,0)
setBgColor(255,255,255)
resetFormat()
Any idea at all ????

Re: Replacing a String

Posted: Mon Jan 31, 2011 4:21 am
by tsuujin
just use selectString(line,1)

Re: Replacing a String

Posted: Mon Jan 31, 2011 6:15 pm
by Theiwar
That did not work for me either Tsuujin.

Perhaps if someone could post an example of how they have accomplished this?

Thanks for the help on this everyone, I'm pulling my hair out trying to figure out why its not working.