Trigger to save to variable

Posted by Halig on Sun 22 Feb 2015 01:21 PM — 11 posts, 37,121 views.

Portugal #0
Hello. I have another question, cause i manage to put it work only in one situation.

Reorx Bla 106 761 0 0 1205 0

This is the MUD information. How can i save the value, in this case, 761? I know how to save it to a variable. Everything works if the case is that, but if anything changes in that sentence, for example:

Reorx Bla 106 761 0 106 1205 0

It changed the 0 to 106. If that happens, the variable that has the 761 saved, doesn't changed anymore. My trigger is as followed:

<triggers>
<trigger
enabled="y"
expand_variables="y"
match="Reorx Bla (.*) (.*) (.*) (.*) (.*) (.*) (.*)"
regexp="y"
send_to="12"
sequence="100"
>
<send>hours = "%2"

SetVariable("hours", hours)</send>
</trigger>
</triggers>
Australia Forum Administrator #1

 match="Reorx Bla (.*) (.*) (.*) (.*) (.*) (.*) (.*)"


That's a confusing regexp. How about detecting numbers if that's what you want:


 match="Reorx Bla (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+)"



Quote:

... the variable that has the 761 saved, doesn't changed anymore.


The variable called "hours"?
Portugal #2
Yes Nick. It was a problem with that. I just seen your answer, but i did it this way:

<triggers>
<trigger
enabled="y"
expand_variables="y"
match="Reorx Bla 106 (.*)"
regexp="y"
send_to="12"
sequence="100"
>
<send>teste = "%1"

firstWord = string.match(teste, "^(%w+)")

SetVariable("hours", firstWord)</send>
</trigger>
</triggers>

And it seems to be working. I'll test what you sayed.
Thank you.
Portugal #3
Hello again. Still have problems with this.

Reorx__________Bla__(.*)__(.*)___(.*)____(.*)____(.*)___(.*)

If you see closely, the spaces between the wildcards are really there. If i don't put them, the trigger doesn't match anythig. My problem besides collecting those numbers it, if let's say the wildcard 3 changes from one to two digits, then the space between the wildcard 3 and 4 changes, if goes from 4 spaces to 3 spaces. How can i collect these changing variables?
Thank you
Amended on Wed 25 Feb 2015 05:20 PM by Halig
Australia Forum Administrator #4
Instead of putting a single space in the regexp, do something like:

\s+

That means "one or more spaces".
Portugal #5
Hi Nick. Thank you, but i didn't understand. Doing something like this:

Reorx Bla 106(\s+)(.*)(\s+)(.*)(\s+)(.*)(\s+)(.*)(\s+)(.*)

Then i've put this for testing:

a = "%1"
b = "%2"
c = "%3"
d = "%4"
e = "%5"

SetVariable("a", a)
SetVariable("b", b)
SetVariable("c", c)
SetVariable("d", d)
SetVariable("e", e)

Cause i need those variables, and only the b caught anything, and caught the all sentence.
USA #6
That's where the less greedy regex Nick used with \d in his very first response is useful. Your .* is capturing the entire line, white space and everything because that's what it's designed to do, you need to use a less greedy expression if you want to pull out the center of a changing string of text.
Australia Forum Administrator #7
Exactly.

.* matches everything, including spaces.

Did you not try \d ?

Obviously not judging by your recent post.

I don't make these posts just to amuse myself you know, you are supposed to try out my suggestions.
Portugal #8
Hi Nick. Ofcourse i've tryed what you said, if tried endless ways. I won't come here to ask for help, if i didn't try what you and other people say. That will be making you all loosing time.
Gonna try all, again.
Portugal #9
Reorx Bla 106(\s+)(\d+)(\s+)(\d+)(\s+)(\d+)(\s+)(\d+)(\s+)(\d+)(\s+)(\d+)

I've tried like this Nick. And still can't get the variables.

a = "%1"
b = "%2"
c = "%3"
d = "%4"
e = "%5"
f = "%6"

SetVariable("a", a)
SetVariable("b", b)
SetVariable("c", c)
SetVariable("d", d)
SetVariable("e", e)
SetVariable("f", f)
Portugal #10
Hi. I've manage to get that working, with the help on the forum. I was doing something wrong.