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


Joined: 14 Aug 2002
Posts: 3

PostPosted: Sun Nov 30, 2003 11:19 am   

check my list of defences
 
Hi - Im looking to compare two stringlists - a master list, and a current list which is created by typing a command which lists what defences i have up.

what i want is for each line of text in the master list to echo a single word back to screen if it ISNT in the curent list.

e.g. if the defence text 'you are hovering above ground' is not present in the current list I would see 'LEVITATE' reminding me to do so.

I understand the principle of comparing using ismember but cant figure out how to neatly store the single word echoes along with the text in the master list.
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Sun Nov 30, 2003 12:48 pm   
 
You have three options: 1) create a third list that contains the one word reminders in order for each item in the master list, 2) convert the master list into a record variable where the keys are the MUD messages and the values are the one word reminders, or 3) just use the MUD message already stored into the master list as the echo instead of a separate one word reminder.

Number two gets complicated a bit because the keys would contain more than one word. I believe you already have the general idea of how to do number three:
#FORALL @masterList {#IF (!%ismember("%i", @currentList)) {#SAY %i}}

which is to iterate through each item in the master list (using #FORALL) and find out if each one is also in the current list. If one is not in the current list, just output the current item of the master list that we are considering (%i).

The first option is similar to the third, except that you need to consult another list to find out the message:
#FORALL @masterList {#IF (!%ismember("%i", @currentList)) {#SAY %item(@reminderList, %ismember(%i, @masterList))}}

The trick here is that, since #FORALL gives you access to the actual item in the list that is being considered, not its position, we need to find out its position in the list. For that, we use %ismember which will also return the items position in the list if it is found. Assuming that @reminderList has all the one word reminders corresponding to each item in @masterList in the corrrect order, then we just need to pass this value to %item to get the correct message to output.

I'll let you find out how to implement the second option. For that, you should look into record variables, #LOOPDB, and %db.
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