Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
Fizban1216
Apprentice


Joined: 03 Feb 2007
Posts: 170

PostPosted: Tue Jun 08, 2010 5:16 am   

Help with An Alias
 
Trying to make an alias that when used does:

order x.dancer kill 'target'
order all kill 'target'
assist

x should be a number 1-4, it should be 1 the first time its used, then become, 2, then 3, then 4, then return to 1.

have this:

Code:

#IF ($dancer != 4) {
  #MATH $dancer ($dancer + 1)
} {
  $dancer = 1
}
order $dancer.dancer kill %params
order all kill %params


But when used it sends:

ERROR: Syntax error in Alias: ok : invalid local variable: dancer
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Tue Jun 08, 2010 5:32 am   
 
If you want this alias to remember that it has been used in the past then you need to use a regular variable and not a local variable.

$ denotes using a local variable @dancer would be for reading a regular variable and dancer=1 would signify setting @dancer to 1.

It just looks like your mind was elsewhere when you tried this. Wink
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
GeneralStonewall
Magician


Joined: 02 Feb 2004
Posts: 364
Location: USA

PostPosted: Tue Jun 08, 2010 6:17 am   
 
It's as Arminas said. Local variables only exist in the script (and scope) they're created in; They do not persist afterward. This would indeed be a case where you would use a regular variable.
Reply with quote
Fizban1216
Apprentice


Joined: 03 Feb 2007
Posts: 170

PostPosted: Tue Jun 08, 2010 12:30 pm   
 
This seems to work, might not be the best way, but does work:

Code:

#IF (!@dancer) {
  dancer = 1
} {
  #IF (@dancer != 4) {
    #MATH dancer (@dancer + 1)
  } {
    dancer = 1
  }
}
order @dancer.dancer kill %params
order all kill %params
assist
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Tue Jun 08, 2010 1:36 pm   
 
That's perfectly fine.

I have two tips, but this is just for general improvement of your scripting skills. What you have is good, and these tips won't make it "better" in any measurable way. First tip is: you don't really need the #MATH command. That command still exists for backwards compatibility with Zmud. But you can do math equations without #MATH. For instance, you could just do:
Code:
dancer = (@dancer + 1)

The second tip is just because I'm a paranoid programmer. I worry about things happening that shouldn't happen. Even if I know the rest of my code won't make it happen. Liike, what if @dancer somehow accidentally got assigned a value greater than 4. So instead of testing whether @dancer equalled 4, I would test whether it was less than 4:
Code:
  #IF (@dancer < 4) {


Like I said, I'm a paranoid programmer Very Happy
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Wed Jun 09, 2010 12:07 am   
 
That's not paranoia, that's Best Practice. They write books about this sort of thing, with the foreknowledge that most programmers and particularly most GAME programmers are exceedingly lazy and/or daring enough to do things the non-standard/unintended way in order to wring out that list bit of speed (which isn't at all helped any by the gargantuan plateaus of hardware technology we have nowadays).
_________________
EDIT: I didn't like my old signature
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Wed Jun 09, 2010 12:17 am   
 
Quote:
most programmers and particularly most GAME programmers are exceedingly lazy and/or daring enough to do things the non-standard/unintended way in order to wring out that list bit of speed

Hey, I resemble that remark!
Reply with quote
Taz
GURU


Joined: 28 Sep 2000
Posts: 1395
Location: United Kingdom

PostPosted: Wed Jun 09, 2010 8:04 pm   
 
Zugg wrote:
Quote:
most programmers and particularly most GAME programmers are exceedingly lazy and/or daring enough to do things the non-standard/unintended way in order to wring out that list bit of speed

Hey, I resemble that remark!
Did you really mean resemble or were you meaning to put resent?
_________________
Taz :)
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum 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