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


Joined: 23 Feb 2009
Posts: 8

PostPosted: Sun Dec 19, 2010 7:36 pm   

Matching items from a string list to a database variable
 
Hello, and thanks in advance for any advice given. I literally drool over what little bits I can understand off of these forums. Love it.

My situation: I have a string list with people's names. These are people I consider friends in the mud. I also have a database variable with a huge list of names as well. These are pretty much the names of everyone I've ever seen. So regardless of the database variable value, everyone on my string list will be found named in the database as well.

Now, when I walk into a room, I do a check to see who is there. I've got a script that takes all the names of the people there, and adds them to the database variable if they aren't already listed, and gives the value of each person in the room a 1. The values of all other names in the database variable are 0.

So, I do a check to see if someone from my string list @friends has a value of 1 in my database @peoples. If it does, I take an action.

Code:

#if (@seekingFriends) {
  #forall @friends {
    #if (@peoples.%i > 0) {
      greet %i
      #print %ansi(high,yellow)"[Friend Found!]: Greeting "%ansi(high,green)%i%ansi(high,white)"."
      #break
    }
  }
}


I realize this will only greet one person, it performs perfectly for what I want it to do.

Here's my question: What if nobody from @friends matches @peoples, and I want to take a different action. For example, if there are no matches, I want to just SHRUG, or do any sort of action. How and where would I insert that into the code? I've tried to put things in several different places and I can't figure it out. It either keeps looping because I don't understand how to properly break it, or it screws up the initial matching, I just don't know how to code that.

I had someone help me put this code snippet together, so while I vaguely understand what I'm doing here, I can't claim I'm competent enough to fully understand it.
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Dec 20, 2010 1:10 am   
 
I find your system a bit awkward, but if it works for you, that's fine.

The way you have it set up, what you will need to do is set a variable when you find a friend in the list. Then, after the loop, you test whether the variable has been set. If it has not been set, you do your alternative action.
Reply with quote
VasoolXanatov
Newbie


Joined: 23 Feb 2009
Posts: 8

PostPosted: Mon Dec 20, 2010 3:26 am   
 
I imagine my whole set of scripts is a bit awkward. I'm a couple weeks into learning how to script and I've been having so much fun I'll spend literal hours on end and not even realize it. So yeah, I just peek at scripts here and there, steal ideas, study how they work, etc. It probably leads me to doing things strangely.

Also, thanks. I found a work around earlier by adding all the values up and if they still added up to 0 doing my alternative action, but it seemed to slow things down a bit. I'll try your suggestion.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Mon Dec 20, 2010 9:06 am   
 
You could always do this...

Code:
$friends=@friends
#WHILE ($friends) {
   $buddy=%pop($friends)
   #IF (@{people.$buddy} > 0) {
      print stuff
      #ABORT
   }
}
shrug


The Abort -should- cancel anything after the loop as well as just break out of the loop, and it allows for failure commands if the loop gives no results.
_________________
Discord: Shalimarwildcat
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