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
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Mon Jun 09, 2003 12:41 am   

what'd I do wrong?
 
quote:

#TRIGGER {^Obvious ({exits|paths}): (*).$} {
Room.exits = %replace( %2, " ", "|")
#forall @Room.exits {#if (%ends( %i, "*")) {Room.exits = %replace( @Room.exits, %i, %concat( "<color yellow>", %leftback( %i, 1), "</color>"))} {Room.exits = %replace( @Room.exits, %i, %concat( "<color gray>", %i, "</color>"))}}
Room.exits = %replace( @Room.exits, "|", " ")
#sub {<color white>Obvious %1:</color> @Room.exits}
}



The above trigger processes a line like so:

Obvious exits: northeast* east* southeast* south* southwest* west* northwest*

It's supposed to remove the * from directions (this denotes whether the direction is lit or not), and color lit directions yellow, unlit directions grey, and the tag white. Now, it works for the most part, except that the northwest* and southeast* directions only get the latter portion of the direction (ie, west* and east*) colored. They color fine if it's an unlit direction.

Anyone see a problem with this trigger?


li'l shmoe of Dragon's Gate MUD
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Mon Jun 09, 2003 2:24 am   
 
%replace(s,p,r)
return s with all occurrences of p replaced with r

So, whenever you replace east* with <color yellow>east</color>, you also replace northeast* and southeast* if they come after east*. (If northeast* or southeast* came before east*, the * would already be stripped.)

When the original exit is unlit, and you replace east with <color gray>east</color>, you also replace northeast, northeast*, <color yellow>northeast</color>, <color gray>northeast</color>, southeast, southeast*, <color yellow>southeast</color, and <color gray>southeast</color> whether they've been processed or not.

Back to the drawing board.

Perhaps two variables and #ADDITEM?

LightBulb
Advanced Member
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Mon Jun 09, 2003 3:37 am   
 
hmm, maybe not. After working with it some more since I posted, I think I might be able to rework the replacement portion using %replaceitem(). That should limit the scope of the change to the one element without getting too intensive...

man, can't believe I didn't see that one

li'l shmoe of Dragon's Gate MUD
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Mon Jun 09, 2003 4:37 am   
 
We all miss that with replace from time to time. Rather then playing with %replaceitem stick with the #FORALL structure. It goes through the list in the order it is there and once started the original list variable can be modified freely. This is like having a free variable you don't have to unassign.

#forall @Room.exits {#if (%ends( %pop(Room.exits), "*")) {#ADDITEM Room.exits %concat( "<color yellow>", %leftback( %i, 1), "</color>"))} {#ADDITEM Room.exits %concat( "<color gray>", %i, "</color>"))}}
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Wed Jun 11, 2003 3:44 am   
 
quote:

We all miss that with replace from time to time. Rather then playing with %replaceitem stick with the #FORALL structure. It goes through the list in the order it is there and once started the original list variable can be modified freely. This is like having a free variable you don't have to unassign.

#forall @Room.exits {#if (%ends( %pop(Room.exits), "*")) {#ADDITEM Room.exits %concat( "<color yellow>", %leftback( %i, 1), "</color>"))} {#ADDITEM Room.exits %concat( "<color gray>", %i, "</color>"))}}



Heh, I assume you didn't test it (as evidenced by the 2 extra closing parentheses)? I know you wrote proper code which should work, but it appears that %pop() is bugged when used on datarecord keys containing stringlists. Specifically, it doesn't look like the popped item gets returned although it and the remaining portion of the list are deleted. This results in your code always evaluating to false and the list of room exits reduced to the last processed.

li'l shmoe of Dragon's Gate MUD
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sat Jun 14, 2003 3:48 am   
 
Finally got time to work up a fix. In this example, the list was generated from trigger output. Instead of using %pop(), simply replace the #FORALL condition with a %replace() function and use a simple %i in place of %pop(). No variable required and you can build the exits variable as you go through the exits.

li'l shmoe of Dragon's Gate MUD
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