|
kidaraine Newbie
Joined: 29 Aug 2012 Posts: 5
|
Posted: Wed Aug 29, 2012 5:00 pm
Little help with an Alias please... |
I've been trying to figure this out for a couple hours now.
I get that I need some sort of variable or %item or something like that, maybe.
What I am trying to do is set up an eat alias. When I tell it 'eat' I want it to take Meat|Fruit out of my pouch and eat it. Normally I just carry meat which makes this process easy, but fruit is lighter and I can carry more of it. I've been trying to figure out how to set this up, but the more I look around trying to figure this out, the more confused I get.
Help? |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4662 Location: Pensacola, FL, USA
|
Posted: Wed Aug 29, 2012 5:11 pm |
#ALIAS eat {get %0 from pouch;~eat %0}
you have to escape out the alias name if you plan on using it within the alias (which the ~ does), otherwise just call it something other than eat, like food |
|
_________________ Discord: Shalimarwildcat |
|
|
|
kidaraine Newbie
Joined: 29 Aug 2012 Posts: 5
|
Posted: Wed Aug 29, 2012 6:14 pm |
Wouldn't that select anything in the pouch though? My confusion lies in getting it to select only the food items in a variable list depending on which food is currently in the pouch, and not selecting something else that might be in the pouch like a drinking flask or ticket.
|
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4662 Location: Pensacola, FL, USA
|
Posted: Wed Aug 29, 2012 6:29 pm |
ahhh, well in that case, do some error checking
#IF (%ismember(%0, @foodlist)) {get and ~eat} |
|
_________________ Discord: Shalimarwildcat |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Wed Aug 29, 2012 6:59 pm |
If you are going to use %0, you're opening up your code to the possibility of multiple arguments. If you are not using multiple arguments, this means that your code could fail unexpectedly via typo, bug, or simply because it executed in the middle of a code change or you forgot about a change made long ago. Since you are only operating on one item at a time, it's better to stick with %1 since %1...%99 variables are limited to one-word parameters (use of quotes aside).
However, aliases won't include parameters not referenced in their code so any extra parameters would be tacked on to whatever the alias expanded to. In Shalimar's example, there'd only be a %1 reference so a mistake like "eat meat cheese" would then end up becoming "get meat;eat meat cheese". To prevent this, you can simply tack on a dummy reference at the end of your real code:
#IF (%ismember(%1,@foodlist)) {get %1;eat %1}
#noop %-2
It really doesn't matter what command you use, so long as you get the variable reference somewhere in there. |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4662 Location: Pensacola, FL, USA
|
Posted: Wed Aug 29, 2012 10:22 pm |
oh... %-1 is the better version of %0 isnt it?
my zMUD kludging days are ancient history |
|
_________________ Discord: Shalimarwildcat |
|
|
|
kidaraine Newbie
Joined: 29 Aug 2012 Posts: 5
|
Posted: Wed Aug 29, 2012 10:41 pm |
Ok, I must ask you to bare with me as I have very little idea of what I am doing. I know I don't need the class but I have several other things going in it later to keep things organized for my sanity. I hope that I am not misunderstanding the use of the class in that regard. I will feel extremely silly then. lol
Anyway, this is what I have, I already have the @foodlist variable, what am I doing wrong?
#Class {Standard Aliases}
#ALIAS eat {get %1 from pouch;~eat %1
#IF (%ismember(%1, @foodlist)) {get %1 and ~eat %1}
#noop %-2}
#Class 0 |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4662 Location: Pensacola, FL, USA
|
Posted: Wed Aug 29, 2012 11:08 pm |
you have the get and eat on there twice, once before the check, and one in the check
|
|
_________________ Discord: Shalimarwildcat |
|
|
|
kidaraine Newbie
Joined: 29 Aug 2012 Posts: 5
|
Posted: Wed Aug 29, 2012 11:33 pm |
So, should I take out the first one? Something like this:
#Class {Standard Aliases}
#ALIAS eat {#IF (%ismember(%1, @foodlist)) {get %1 from pouch; ~eat %1}
#noop %-2}
#Class 0
Or this:
#Class {Standard Aliases}
#ALIAS eat {get %1 from pouch;~eat %1
#IF (%ismember(%1, @foodlist))
#noop %-2}
#Class 0
When I send what I had before it comes up with
Get from pouch
Eat
To which I get
Get what from pouch?
Eat what?
Or something like that anyway. Sorry to be difficult, I am just trying to understand how these things are supposed to go together. |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4662 Location: Pensacola, FL, USA
|
Posted: Thu Aug 30, 2012 12:08 am |
the first option would be the one you want
and you do have to specify a food type with the alias , "eat apple"
'eat' all by itself would give the results you describe
if thats not the case... perhaps the foodlist contains items with multiple words? apple will not match "yellow apple"
and was the variable actually @foodlist? if not change it to reflect the true variable |
|
_________________ Discord: Shalimarwildcat |
|
|
|
kidaraine Newbie
Joined: 29 Aug 2012 Posts: 5
|
Posted: Thu Aug 30, 2012 12:25 am |
Oh, now that makes sense. And yes the variable is foodlist.
And now it works! Thank you so very much for the help. |
|
|
|
|
|