Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
rto0288
Beginner


Joined: 23 Apr 2006
Posts: 11

PostPosted: Tue Jan 09, 2007 7:51 pm   

Complicated trigger issues (detailed)
 
the MUD I play has butterflies floating around all over the place and I am writing a script to count how many are in any given room. There are 5 different kinds of butterflies but that's not much of a problem as I'm pretty comfortable with regex now. My main issues are two (but each kinda the same problem): triggers multiple times per line don't do what they're supposed to. For example, I have a trigger which is normally disabled until a roomname pops up then it starts looking for the word 'butterfly ' (with a space after it, I'll touch on that at the end of this post). Each time it sees 'butterfly ' it adds 1 to a variable called 'butterflies'. This works perfectly until a line contains the word butterfly multiple times, in which case it still only adds 1 to @butterflies. To test if the trigger was firing on each word I threw in a #CW red and found that it does highlight each 'butterfly ' red, just doesn't count them all... So that's issue #1, here's #2: if there is more than one of the same kind of butterfly in the room the MUD will say something along the lines of: There are (n) (type of butterfly) butterflies here. So, naturally I also have a trigger which looks for {($bFlies:\d+) .* butterflies}. Again, works fine, adds $bFlies to @butterflies BUT if there are two or more occurrences of this trigger it will highlight them but it will only add the latter number. The first number seems to be ignored. If anyone can help I'll love ya.

Oh also, as promised, I'm going to touch on that other issue. My trigger which fires on 'butterfly ' I had initially set to fire on 'butterfly' (without the trailing space) but for some reason whenever it fired it would loop infinitely. As I'm writing this it's occurring to me that it was probably due to the #SAY command which may have caused the trigger to repeatedly see the last line ('butterfly'). I'll actually have to go test that right now but I'll leave this in my post in case anyone has any input on the matter.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Tue Jan 09, 2007 8:10 pm   
 
You could try using the reparse trigger option. What you could also do is something like the following:

#local $previous
#forall %replace(%line," ","|") {#if (%i="butterfly") {#add Butterflies 1};#if (%i="butterflies") {#add Butterflies $previous};$previous=%i}
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
rto0288
Beginner


Joined: 23 Apr 2006
Posts: 11

PostPosted: Tue Jan 09, 2007 9:32 pm   
 
heh tried reparse... freezes the whole application. I'm unclear on your second idea. It seems to me to be trying to make my two triggers into one which just picks apart each line. It's a nifty idea for sure but for now I'm really bothered by the multi-fire problem and dying to find a resolution. It's weird, these triggers work fine so long as their patterns don't occur twice on the same line, I imagine there must be some simple solution to this... If the MUD sends the line "There is a red admiral butterfly here. There is an indigo nightfire butterfly here." the 'butterfly ' trigger should fire twice, incrementing @butterflies by 2. I feel like the solution to the problems with this trigger should be the same for the other trigger (or similar). Thanks for the reply Fang, I appreciate the help, I'm open to any and all other ideas you have.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Tue Jan 09, 2007 9:49 pm   
 
The script above just takes the whole line (since your trigger only fires once per line) and parses it to check for more than one pattern. If the reparse option isn't working, that's the best I can think of.
Reply with quote
rto0288
Beginner


Joined: 23 Apr 2006
Posts: 11

PostPosted: Tue Jan 09, 2007 10:32 pm   
 
Fang, you're a genius :) I didn't fully get it the first time around but I did some reading on %replace and was enlightened. Thankya buddy big help!
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net