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
Berill
Newbie


Joined: 29 May 2003
Posts: 6

PostPosted: Thu May 29, 2003 8:37 am   

Capturing into a string list
 
Hey,

What I am trying to do is capture the exits for the rooms in my MUD into a string list variable. The line in the room description looks like this:

Exits: north, south, east, west, northeast, northwest, southeast, southwest.

It doesn't always have all of them though, and the last one in the line is always followed by the period. This is the trigger that I came up with that I thought would capture all of them into a string list variable:

#TRIGGER {^Exits~:%s(*)} {
#VAR Exits {%1}
#VAR Exits %replace( @exits, "north{ |.} ", "north|")
#VAR Exits %replace( @exits, "south{ |.} ", "south|")
#VAR Exits %replace( @exits, "east{ |.} ", "east|")
#VAR Exits %replace( @exits, "west{ |.} ", "west|")
#VAR Exits %replace( @exits, "northwest{ |.} ", "northwest|")
#VAR Exits %replace( @exits, "northeast{ |.} ", "northeast|")
#VAR Exits %replace( @exits, "southwest{ |.} ", "southwest|")
#VAR Exits %replace( @exits, "southeast{ |.} ", "southeast|")
#VAR Exits %leftback( @Exits, 1)
}

This only captures it into a regular text variable though, not a string list. Any ideas why it doesn't? Or even a better way to do it?

Thanks!
D
Reply with quote
Serentus
Apprentice


Joined: 28 Sep 2001
Posts: 103
Location: USA

PostPosted: Thu May 29, 2003 10:43 am   
 
Try
#TRIGGER {^Exits~:%s(*)} {
#VAR Exits {%1}
#VAR Exits %replace(@Exits,", ","|")
#VAR Exits %leftback( @Exits, 1)
}

Also if the line always ends in a period you can get rid of the %leftback if you put the period in the pattern.

#TR {Exits~:%s(*).} {}

-Serentus-
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Thu May 29, 2003 3:59 pm   
 
You can't use { |.} in %replace. The variable can all be done in one operation, however.
#TRIGGER {^Exits~:%s(*).} {#VAR Exits {%replace( "%1", ", ", "|")}}
There's probably a fixed number of spaces after : and it would be better to use the actual spaces instead of %s, since * can also match spaces.


LightBulb
Advanced Member
Reply with quote
tacturnal
Beginner


Joined: 28 May 2003
Posts: 21
Location: USA

PostPosted: Thu May 29, 2003 6:01 pm   
 
that all looks fine and good if your exits are seperated by commas or spaces
if your exits are just one chunk of letters
you need to seperate them into individual variables,and then concatonate them with | in between if you want them to be a list

Here is how I know to do it
Perhaps a code guru here has a better way

Trigger Pattern :
~[Exit &exits~] (This pulls the word of exits from the mud output and saves to the variable @exits .. this is how my mud looks, yours may be different)

#loo 6 {#var exit[%repeatnum] {""}}
This clears all the variables

#loo %len(@exits) {#var exit[%repeatnum] {%left(@exits,1)}
exits=%delete(@exits,1,1)}
This seperates the @exits variable to @exit1 @exit2 @exit3 @exit4 @exit5 @exit6 (my mud only has nsewud)

Now that you have the word of exits seperated into 6 different variables, and each are a direction, you put them all back together, with a | inbetween each one.. that makes it a variable list.. I put alot of %if checks in there to keep the list tidy.

exits=%concat(%if(@exit1,@exit1,),%if(@exit2,"|",),%if(@exit2,@exit2,),%if(@exit3,"|",),%if(@exit1,@exit3,),%if(@exit4,"|",),%if(@exit4,@exit4,),%if(@exit5,"|",),%if(@exit5,@exit5,),%if(@exit6,"|",),%if(@exit6,@exit6,))

so then you just type look
and when the room description with exits comes up
type #var exits
and you will see your exits in a variable list instead of a text variable.

--James
Reply with quote
tacturnal
Beginner


Joined: 28 May 2003
Posts: 21
Location: USA

PostPosted: Thu May 29, 2003 6:05 pm   
 
if you just want to cut and paste, cut and paste this :

#trigger {~[Exit: &exits~]} {#loo 6 {#var exit[%repeatnum] {""}}
#loo %len(@exits) {#var exit[%repeatnum] {%left(@exits,1)}
exits=%delete(@exits,1,1)}
exits=%concat(%if(@exit1,@exit1,),%if(@exit2,"|",),%if(@exit2,@exit2,),%if(@exit3,"|",),%if(@exit1,@exit3,),%if(@exit4,"|",),%if(@exit4,@exit4,),%if(@exit5,"|",),%if(@exit5,@exit5,),%if(@exit6,"|",),%if(@exit6,@exit6,))}

then go and edit the trigger to match your exits display.

--James
Reply with quote
tacturnal
Beginner


Joined: 28 May 2003
Posts: 21
Location: USA

PostPosted: Thu May 29, 2003 6:06 pm   
 
oh crap, sorry, didn't see that you illustrated your exits display, please ignore my posts.. :)
Reply with quote
Berill
Newbie


Joined: 29 May 2003
Posts: 6

PostPosted: Thu May 29, 2003 6:57 pm   
 
Thanks for all your help, its working great now.

Lightbulb, as far as I've seen, there are either one or two spaces after the :, so I couldn't think of better way to match it.

D
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Thu May 29, 2003 7:25 pm   
 
If you can't be sure how many spaces there are, %s is the best choice.

LightBulb
Advanced Member
Reply with quote
kord
Newbie


Joined: 25 May 2003
Posts: 5
Location: USA

PostPosted: Thu Jun 05, 2003 9:12 am   
 
Why would you be using all this concatenation stuff instead of %additem?

Clear the variable at the start of the trigger, i.e. #var exits "", and then #var Exits %additem(@Exits,blah), I mean.

(relative novice to Zmud coding, and coding in general -- honest curiosity here :)


"A plan is just a list of things that don't happen."

--Parker, _Way of the Gun_
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Thu Jun 05, 2003 3:57 pm   
 
It's already been reduced to a single operation using %replace(). See my first response.

There was never any concatenation involved, just a lot of %replace(). In order to use %additem(), you'd need two variables and a looping structure to go through the first (string) variable, pick out the words, and add them to the second (list) variable. It's much easier to just use %replace() to convert the original string-variable to a list-variable.

LightBulb
Advanced Member
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