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


Joined: 19 Aug 2002
Posts: 120
Location: USA

PostPosted: Tue Nov 25, 2003 2:50 am   

Making a list of names with a number associated
 
Ok... I have a command I want to make called "phone".... now with this command, I want to be able to type phone store <name> <number>, and have it store the name and number into a variable. Then, If I type phone call <name>, I want it to "call <number associated with name>", and if I give it no arguements, I just want it to "phone"... It sounded simple until I started trying to make it... but I'm sure it still is relatively simple, would anyone be willing to help me out here?
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Tue Nov 25, 2003 4:05 am   
 
Ok, storing the numbers can be easily accomplished with a record variable. This way, you'll be able to associate each name with its number and easily retrieve a number by name. As for having the alias react based on the arguments you give it, you can use the %1..%n variables for that:

#ALIAS phone {#IF (%1) {#IF (%1 = "store") {#ADDKEY phoneList {%2} {%3}} {#IF (%1 = "call") {call %db(@phoneList, %2)} {#SAY Invalid argument to phone}}} {~phone}}

What the alias does is to first check if %1 is defined. If it is not, then no arguments where given to the command and it just sends "phone" (the ~ is necessary to prevent zMUD from thinking it is a recursive call to the same alias).

If there is an argument, it first checks to see if the first argument is "store". If it is not "store", then it checks to see if it is "call". If it is not "call", then it outputs an error message.

If the first argument is "store", the alias uses the #ADDKEY command to add a new key-value pair to the record variable @phoneList. If the key already exists within the record variable, the #ADDKEY command replaces its value with the new one supploed.

Finally, if the first argument is "call", the alias sends the "call" command to the MUD followed by whatever value is associated with the specified key. To look this value up in the record variable, it uses the %db function.
Reply with quote
Latent
Apprentice


Joined: 19 Aug 2002
Posts: 120
Location: USA

PostPosted: Tue Nov 25, 2003 4:15 am   
 
Thank you very much Kjata, and thank you for the explanation of the alias as well, I AM doing my best to learn how to do this stuff
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