|
horks Apprentice
Joined: 20 Jul 2001 Posts: 127 Location: USA
|
Posted: 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 :)
|
|
|
|
r00t Newbie
Joined: 09 May 2002 Posts: 0
|
Posted: 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. |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: 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 |
|
|
|
|
|