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


Joined: 05 Jul 2012
Posts: 5

PostPosted: Thu Jul 12, 2012 2:57 am   

problems with parameters
 
I'm having problems trying to figure out how to capture command line parameters associated with a alias commands.
The first is to have an alias called "settimer". I'd like it so that I can type in "settimer vampire" and exactly thirty minutes later it issues a message box with "vampire should have already reset". The alias in Zmud looked like: #ALA +30:00 {#MESS 500 (%1 should have reset)} Even with a previous posting's reply, I still can not figure out this alias.

The other parameter problem I'm having is somewhat similar. I'd like to have an alias called "addprayer" such that should I enter "addprayer continual-light", it adds the string "continual-light" to a list variable called "prayerlist". The alias in Zmud looked like: #VAR prayerlist %additem(%literal(%1), @prayerlist).

I think my problem with parameters is not knowing how to capture the parameter from the command line. Would someone give me examples of how to solve both situations described?
Reply with quote
hadar
Apprentice


Joined: 30 Aug 2009
Posts: 198
Location: my apt, in california

PostPosted: Thu Jul 12, 2012 4:29 am   
 
ok here are the 2 alias should work and ill explain everything.
Code:

  <alias name="settimer" id="3979">
    <value>#local $foo
$foo=%concat(%proper(%1)," should be reset")
#ALARM %1 {+30:00} {#mess 500 $foo}</value>
  </alias>

code1-settimer <param> you had it close, i did notice you could not put a %1 in the mess without it messing up a little, so i created a local variable, and concated the string, so that it would parse it before it creates the alarm, and it works perfectly this way, also the alarm needed {} around the time, i also named the timers, so you can have multiple timers running at the same time
Code:

  <alias name="addprayer" id="3982">
    <value>#additem prayerlist %1</value>
  </alias>

for code 2 i was not 100% sure if you wanted to be able to add duplicates (%additem() allows duplicate results)so i just changed it to a simple #additem

any questions please feel free to ask, i think i explained all my work
_________________
if you build it they will come, assuming that they have not already come to build it
Aardwolf Bootcamp
My youtube channel
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Thu Jul 12, 2012 5:01 am   
 
Step 1: concatenate your command code. Concatenation allows you to maintain the proper context for the %1...%99 variables. Doing it like you did above, the %1 is then tied to the #ALARM command and alarms don't have %1...%99 variables. Concatenation comes in two varieties, explicit and implicit. Explicit concatenation uses %concat(), which does not allow compiling and so is quite slow. Implicit concatenation, while faster, is also less safe as your string might wind up being evaluated differently than you intended. To implicitly concatenate, just surround the literal parts with double quotes (ie, "#alarm +30:00 {#mess 500( "%1" should have reset)}").

Step 2: execute the concatenated string. #EXECUTE, or %exec(). Both of these are very slow, so in general if you find yourself thinking to use these then there's almost always a better way to go about doing whatever you wanted to do.
_________________
EDIT: I didn't like my old signature
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Thu Jul 12, 2012 3:31 pm   
 
%concat() can't be compiled? I thought that was only true for exec and eval.
Reply with quote
rloii
Newbie


Joined: 05 Jul 2012
Posts: 5

PostPosted: Fri Jul 13, 2012 1:27 am   
 
In trying all kinds of things, I found this to work for adding a string to the variable list. Why would this not be the simplest solution?

#VAR prayerlist %additem(%1,@prayerlist)

As for the alarm, I found this to work:

#VAR @timer %1
#ALARM {+00:30} {#MESS 500 %concat(@timer," has reset")}

However, in the case of the alarm, the parameter @timer is expanded at the time of the alarm, therefore if you issue an alternate settimer alias prior to the 30 minutes, both alarms will expand the current value of @timer at the time the alarm fires. Is there any way to expand the parameter at the time of the settimer alias so the ALARM trigger will maintain the value of @timer directly rather than pull at the current value of @timer at the time of the ALARM?
Reply with quote
hadar
Apprentice


Joined: 30 Aug 2009
Posts: 198
Location: my apt, in california

PostPosted: Fri Jul 13, 2012 2:23 am   
 
wait are you still using zmud or have you already made the switch to cmud, if you did switch to cmud check the solutions i provided
_________________
if you build it they will come, assuming that they have not already come to build it
Aardwolf Bootcamp
My youtube channel
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