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
vortis
Novice


Joined: 15 Jul 2010
Posts: 39
Location: USA

PostPosted: Fri Mar 16, 2012 2:54 pm   

Searching a variable for specific words
 
Text:
Obvious exits : north, east, south and west.

Pattern:
Obvious exits : %1
This makes %1 = "north, east, south and west."

Trigger:
ExitList = %1
This makes @ExitList = "north, east, south and west."

I want to check @Exitlist to see if 'south' is in the list, and if it is, set another variable @WalkSafe to "Yes"

What is the best way to do this?
Reply with quote
Shezmu
Wanderer


Joined: 23 Apr 2010
Posts: 53

PostPosted: Fri Mar 16, 2012 4:33 pm   
 
This should work. Just going from memory, though.
#if %ismember("south",@Exitlist) {#var WalkSafe "Yes"} {}
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Fri Mar 16, 2012 6:04 pm   
 
Shezmu wrote:
This should work. Just going from memory, though.
#if %ismember("south",@Exitlist) {#var WalkSafe "Yes"} {}


That'd work if it were an item list. "north, south, east, west" is not an item list, though.

You can do it one of two ways.

1. Change ExitList = %1 to ExitList = %subchar(%1,",. ","|") and follow Shezmu's example.
2. Change %ismember in Shezmu's example to %pos.
Reply with quote
Shezmu
Wanderer


Joined: 23 Apr 2010
Posts: 53

PostPosted: Fri Mar 16, 2012 6:20 pm   
 
Once again, Charneus is much better at this than I am. ;)
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Fri Mar 16, 2012 8:23 pm   
 
Two notes:

With Charneus' first option, you will also end up with "and" in your ExitList. If you aren't doing anything else with ExitList, that's fine, but if you decide later to use it for other stuff, you should get rid of "and". You will also end up with several empty values in ExitList which could cause problems if you use it for anything else. There are several ways of avoiding this problem if you think it will use ExitList for anything else.

With Charneus' second option, you have to be careful if you can have exits to northeast, southeast, etc. It looks like this is probably not the case here, but if there are such exits, using %pos() can match the wrong things.
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Fri Mar 16, 2012 8:33 pm   
 
Whoops, good catch, Rahab. I missed the 'and' in the previous post. Time to amend things!

This might be a better solution, in fact.

Code:
ExitList = %null
$Exits = %replace(%1," and ",", ")
#LOOP %numwords($Exits,", ") {#ADDITEM ExitList %word($Exits,%i,", ")}


That way, you'll clear out the exit list upon seeing the trigger line, then you'll add the individual exits properly.

There may be a slightly better way to do this, but I can't think of it at this moment.
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