Replacing a String

Theiwar
Posts: 24
Joined: Sun Dec 12, 2010 3:49 pm

Replacing a String

Post 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()

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

Re: Replacing a String

Post by Heiko »

You haven't selected anything -> replace() does nothing. There are several select functions -> api docs

Theiwar
Posts: 24
Joined: Sun Dec 12, 2010 3:49 pm

Re: Replacing a String

Post 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()

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

Re: Replacing a String

Post 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()

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

Re: Replacing a String

Post by Vadi »

Just use selectString(line, 1)

Theiwar
Posts: 24
Joined: Sun Dec 12, 2010 3:49 pm

Re: Replacing a String

Post 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()

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

Re: Replacing a String

Post by Vadi »

No, you'd want selectCaptureGroup(1)

Theiwar
Posts: 24
Joined: Sun Dec 12, 2010 3:49 pm

Re: Replacing a String

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

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

Re: Replacing a String

Post by tsuujin »

just use selectString(line,1)

Theiwar
Posts: 24
Joined: Sun Dec 12, 2010 3:49 pm

Re: Replacing a String

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

Post Reply