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
horks
Apprentice


Joined: 20 Jul 2001
Posts: 127
Location: USA

PostPosted: Mon Apr 08, 2002 9:06 am   

Comparing Lists
 
I have two list variables, one full of names of mobs I want to kill (call it @mobs), and another of items in the room (call it @items). Items can be anything; they can be armour/weapons/mobs/stationary objects. I want to compare these two lists (maybe using the #IF command?) and perform an action if an item exists in both lists. Can anyone tell me how to do it? Thanks :)
Reply with quote
r00t
Newbie


Joined: 09 May 2002
Posts: 0

PostPosted: Mon Apr 08, 2002 4:12 pm   
 
I think this is what you want to do.

#LOOP %numwords( @items) {
#if %ismember( %word( {@items}, %i), @mobs) {say Yup it's there} {say Nope not there}
}

I think that's right but I'm too tired to see stright so someone correct me if I'm wrong.
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Mon Apr 08, 2002 5:05 pm   
 
%numwords and %word are string functions. Since these are both list variables, stick to list functions.
#LOOP %numitems( @items) {
#if %ismember( %item( @items, %i), @mobs) {say Yup it's there} {say Nope not there}
}


The #FORALL command is ideal for this type of thing and will simplify it considerably.
#FORALL @items {#if %ismember(%i,@mobs) {say Yup it's there} {say Nope not there}}



LightBulb
All scripts untested unless otherwise noted
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