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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
vimvam
Newbie


Joined: 03 May 2002
Posts: 2

PostPosted: Mon Apr 01, 2002 3:56 am   

Please help, this SHOULD work, right?
 
This is driving me crazy.
On the mud I play, room names are given in brackets, followed underneath by a complete description of the room along with who or whatever is there, ending with a list of directions. It would look something like this:

[Trackless Wasteland]
Sand, sand, and more sand as far as the eye can see. There are no landmarks and every direction looks the same.
You also see a small orc, a small orc and a large orc.
Obvious exits: north, east, south, west.

Here are my triggers to count the orcs in the room -

#TR {~[Trackless Wasteland~]} {#VA orcs 0;#T+ Catchenemy}

#TR {orc} {#CW 14;#AD orcs 1} {Catchenemy}

#TR {Obvious exits:} {#T- Catchenemy}

Okay, so what that is supposed to do is make it so that every instance of the word 'orc' adds one to the orc variable, but only between the room name and end of the room description by turning the 'orc' trigger on with the room name and off with room exits. Now, when I test it, every instance of the word orc IS colored yellow, which is part of the trigger, but it only counts 1 of them no matter how many times the word appears. Can anyone offer any suggestions as to why this might be?
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Mon Apr 01, 2002 6:50 am   
 
It might be because #CW works differently.

A trigger will only fire once per line but #CW will color multiple instances of the trigger phrase.

LightBulb
All scripts untested unless otherwise noted
Reply with quote
vimvam
Newbie


Joined: 03 May 2002
Posts: 2

PostPosted: Mon Apr 01, 2002 2:53 pm   
 
Hmm, so any suggestions? Is there any other way to count the monsters in the room? Perhaps some other command that will fire multiple times per line? And thanks for the speed reply, Lightbulb. I'd be lost without this forum, as I have no programming skills at all and am just learning ZMUD.
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Mon Apr 01, 2002 4:29 pm   
 
This is a bit of a kludge, but it's the only thing I could come up with. Perhaps someone else will have a better idea.

#TR {orc} {#CW 12;#VAR temp %countlist(%replace(%replace(%replace(%trigger," ",|),",","|"),".","|"));#VAR orcs @temp.orc}
NOTE: There should be a space between the first set of double-quotes.

LightBulb
All scripts untested unless otherwise noted
Reply with quote
vimvam
Newbie


Joined: 03 May 2002
Posts: 2

PostPosted: Mon Apr 01, 2002 5:48 pm   
 
Thanks so much for trying. That one looked pretty complicated from my point of view. Would probably take an hour to fully understand what it's doing. Unfortunately it didn't work. Got me thinking, though, that maybe it would recognize triggers on the same line if they were brand new triggers after each instance of the word orc. At first I thought it was working, but for some odd reason no matter how many are in the room I end up showing 3. Here's what I did:

#TR {~[Trackless Wasteland~]} {#VA orcs 0;#T+ catchenemy}

#TR {orc} {#TEMP {orc} {#AD orcs 1;#TEMP {orc} {#AD orcs 1}} {catchenemy}}

#TR {Obvious exits:} {#SH Orcs: @orcs}

So, trying to create a new trigger with every instance of the word orc that Adds one to orcs variable, deletes itself, then creates a temporary trigger to do it again. Any thought as to why this isn't working? It's probably just my terrible math skills because something seems faulty with the logic.

Thanks
Jim
Reply with quote
itsmarty
Novice


Joined: 29 Jan 2002
Posts: 37
Location: USA

PostPosted: Mon Apr 01, 2002 9:15 pm   
 
There's a trigger state called reparse that will look back over the same line again. It might be in the beta version and I'm at work so I don't have the luxury of checking right now. If so, it's not a solution and I apologize for bringing it up.

Martin
Reply with quote
kognesty
Newbie


Joined: 08 Jan 2001
Posts: 8
Location: USA

PostPosted: Mon Apr 01, 2002 9:36 pm   
 
As stated, if you have the beta version this becomes very easy to do with reparse, but its only in beta. Now, here's what you're going to have to do for the public release to get this all right.
Pattern:
You also see &{mobs}.
Action:
Now the logic for the action is going to be this. In the string we captured mobs there are some words, some of those words are orc, some are not. We want to know how many words are orc, so we are going to check each word in the string to see if its orc, if it is we'll increase a variable by one. Now for the specific syntax (which I can't give, I don't have zMUD infront of me to write it out) you'll need to examine #LOOP, and string manipulation which can be found in the command reference section. If you can't find the solution on your own, or I just confused you to no end, post back and I'll work on it when I get home.

#VAR orcs 0
#VAR pos 1
#LOOP %numwords( @mobs)
{
If(%word( @mobs,@pos)== "orc," || %word( @mobs,@pos)== "orc") {#ADD orcs 1;#ADD pos 1}{#ADD pos 1}
}
How this works. First you capture the text "a small orc, large orc and medium orc" then %numword( @mobs) counts the words according to spaces so you get a number 8. Then #LOOP will do the following 8 times:
Check to see if in the string @mobs the first word is either orc, or orc. If yes then increase orcs by one and pos by one if no just pos, increasing pos insures that when the if statement is run the next time it checks the second word instead of the first again, this will repeat 8 times and you should end up with @orcs equalling 3.
Reply with quote
vimvam
Newbie


Joined: 03 May 2002
Posts: 2

PostPosted: Tue Apr 02, 2002 1:37 am   
 
That worked like a charm, kognesty, thanks SO MUCH and to all that replied so quickly! I never would have thought to look at the #LOOP command and I really didn't want to have to go with the new beta. I'm hopelessly stuck on ver 5.55 and anything else just confuses me. Other than that, Zmud rocks. I wouldn't still be playing MUDS without it. Can't wait for the new mapper, too.

Thanks again all, you'll probably hear from me again. <g>
Jim
Reply with quote
kognesty
Newbie


Joined: 08 Jan 2001
Posts: 8
Location: USA

PostPosted: Tue Apr 02, 2002 4:10 am   
 
quote:

That worked like a charm, kognesty, thanks SO MUCH and to all that replied so quickly! I never would have thought to look at the #LOOP command and I really didn't want to have to go with the new beta. I'm hopelessly stuck on ver 5.55 and anything else just confuses me. Other than that, Zmud rocks. I wouldn't still be playing MUDS without it. Can't wait for the new mapper, too.

Thanks again all, you'll probably hear from me again. <g>
Jim





As I am sure everyone who posts feels, thank you for the complement. And I am thrilled that the solution worked and that I could help. Enjoy the true power of a well built program and keep on mudding.
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Tue Apr 02, 2002 4:47 am   
 
I'm glad someone came up with something that worked for you.

I'm puzzled that the trigger I provided didn't work though. I tested it using
#SHOW You also see a small orc, a small orc and a large orc.
with different numbers and types of orcs. In all tests "orc" was colored by #CW and @orcs had the correct number. I then copied it directly from zMUD to the forum.

*shrug* Anyway, if you've got something working, especially if it's something you understand, that's the main thing.

LightBulb
All scripts untested unless otherwise noted
Reply with quote
vimvam
Newbie


Joined: 03 May 2002
Posts: 2

PostPosted: Wed Apr 03, 2002 2:57 am   
 
Actually, after further testing I found it doesn't work, so I gave up and went with the Beta to try Reparse. However, everytime I make a trigger set for reparse Zmud crashes on me with the next action, so I give up. Still very grateful to all those who tried.
Reply with quote
vimvam
Newbie


Joined: 03 May 2002
Posts: 2

PostPosted: Wed Apr 03, 2002 4:16 am   
 
Further explanation...that trigger doesn't work because the (You also see (%*).) can be split up over several lines. This is what the output would look life from my mud:

[Trackless Wasteland]
The constantly shifting sands provide no landmarks for you to get you bearings, making navigation extremely difficult. You also see a large orc, a treasure chest, some bronze coins, a rusty dagger, some moth-eaten robes, a small orc, a squirrel, and a small orc.
Possible exits: any.

So, what I'm trying to do is count the number of times "orc" shows up on the paragraph between the room names and the room exits. I thought I could do that very easily with reparse, but every time I create a reparse trigger Zmud just crashes so I assume it's still being worked on in the BETA.
Any suggestions all?
Reply with quote
vimvam
Newbie


Joined: 03 May 2002
Posts: 2

PostPosted: Wed Apr 03, 2002 5:01 am   
 
Think I may have found the answer with some experimentation and looking at previous posts...probably a simple fix for most but seems like major triumph to me. See if ya'll think this will work...
I set several triggers to account for multiple lines.

Patterns:
You also see (%*).
You also see (%*)$(%*).
You also see (%*)$(%*)$(%*).

Triggers:
#VA enemies {%1}
#VA enemies {%1 %2}
#VA enemies {%1 %2 %3}

And then on room exits, I use the #LOOP trigger kognesty suggested to count the number of orcs. The above patterns only cover output of three lines and it can be much higher, so I guess I'll just keep creating them down the line. Anyone forsee any problems?
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Wed Apr 03, 2002 3:46 pm   
 
With your current set of triggers all three will fire when you have three or more lines of mobs/items. Since each one zeros @orcs it will probably work though.

Another problem is that you will eventually run into a description that's just the right length to put the linebreak in the middle of "You also see" or right at the end of it.

The best solution I can see is to trigger on [Trackless Wasteland] to zero @orcs and enable a class and on Obvious exits/Possible exits to disable it. You can then use the trigger I suggested, with #ADD instead of #VAR, to count the orcs. I also changed the replace value for commas and periods to a nullstring since they always have a trailing space unless they are at the end of a line. It goes like this:

#TR {~[Trackless Wasteland~]} {#VAR orcs 0;#T+ orcs}
#TR {orc} {#CW 14;#VAR temp %countlist(%replace(%replace(%replace(%trigger," ",|),",",""),".",""));#ADD orcs @temp.orc} {orcs}
#TR {{Obvious|Possible} exits} {#T- orcs}


I should probably explain how this trigger works. It starts by capturing the line using the predefined variable %trigger. It then employs the %replace() function to remove commas and periods and change spaces into pipes (|), thereby converting the trigger-line to a stringlist. Next, the %countlist() function counts how many times each word appears in the string list and this is captured in the database variable @temp. The number of orcs on each line is then in @temp.orc and this value is #ADDed to @orc.

Script has been tested and does work.

LightBulb
All scripts untested unless otherwise noted
Reply with quote
heidi
Newbie


Joined: 04 May 2002
Posts: 1

PostPosted: Wed Apr 03, 2002 6:42 pm   
 
Good job, LightBulb. I worked a bit on this last night and couldn't find anything until I reviewed how your script worked and uncovered a different way that might be a little faster:

#TR {You also see} {#VAR orcs 0;#T+ orcs}
#Trigger {orc} {#Add orcs %max(%numwords(%trigger," orc") -1,0)} {orcs}
#TR {{Obvious|Possible} exits} {#T- orcs}

You may not need the %max function because the trigger will eliminate any lines that don't have the phrase " orc" in it. I have tested this using the #show command and it seems to work.

Thanks,

El_Dickman
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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