 |
Fergal1982 Wanderer
Joined: 08 Aug 2005 Posts: 70
|
Posted: Fri Sep 09, 2005 5:40 pm
looping an alias |
hey guys,
im looking to create a simple alias which will loop a number of times determined by a variable entered along with the command.
For instance, if i want to buy 10 copies of a powder, and then put those ten powders into a pouch, i want the alias to loop 10 times.
I could make a static one for 10, but what about the occassions where i want to purchase 20, or 35?
Thanks
Fergal |
|
|
|
 |
charneus Wizard

Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Fri Sep 09, 2005 5:53 pm |
I have something like that...
| Code: |
| #ALIAS buypow {#var powder %1; #loop @powder {buy powder;put powder in pouch};powder = 0} |
Then the way you would execute it would be:
buypow 10
That will buy 10 copies of powder and put them in the pouch.
Don't copy my example verbatim - I'm sure your MUD uses a different syntax. Just change the "buy powder;put powder in pouch" accordingly. :)
Charneus |
|
|
|
 |
Fergal1982 Wanderer
Joined: 08 Aug 2005 Posts: 70
|
Posted: Fri Sep 09, 2005 5:56 pm |
ok. thats good. but how about if i want to add in another variable of the powder name?
|
|
|
|
 |
charneus Wizard

Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Fri Sep 09, 2005 6:00 pm |
You can change anything in that code, actually. You can change the variable name, the alias name...
I think that's what you're asking.
If that's not, please elaborate what you mean.
Charneus |
|
|
|
 |
Fergal1982 Wanderer
Joined: 08 Aug 2005 Posts: 70
|
Posted: Fri Sep 09, 2005 6:05 pm |
sorry, what i mean is, i want to set up a single alias, but use it with multiple powder names, would i just change the instances of powder to %2?
|
|
|
|
 |
Fergal1982 Wanderer
Joined: 08 Aug 2005 Posts: 70
|
Posted: Fri Sep 09, 2005 6:12 pm |
that actually seems to work, what i suggested, but i have a problem.
When we buy from the shop, we have to use the powder number (eg salt6505), but when it goes into your inventory, it seems to gain a different number. appearing in inv as below
| Code: |
135 gold coins, "gold12053".
11 portions of relaxant salt, "salt11773".
A health potion, "potion5825". |
so i need to set it up with three variables now.
%1 the quantity
%2 the stock number
%3 the powder name.
giving:
| Code: |
| #ALIAS buypow {#var powder %1; #loop @powder {buy %2;inscrip %3};powder = 0} |
unless anyone can think of a better way to do this |
|
|
|
 |
charneus Wizard

Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Fri Sep 09, 2005 6:22 pm |
Hmmm...
You -could- make a trigger to identify it in the shops... (the following is just a loosely based example - feel free to change it to work for you):
| Code: |
#TRIGGER {(%d) portions of relaxant salt, %s "&stock".}
#ALIAS buypow {#var powder %1;#loop @powder {buy @stock;inscrip salt};power = 0} |
Only thing is, you'd have to make a trigger and alias for each variant of powder. Perhaps more of an example from your end would be feasible. If you can provide us with more examples of powder, we could ultimately create an alias to make your mudding experience a little easier. :)
Charneus |
|
|
|
 |
Fergal1982 Wanderer
Joined: 08 Aug 2005 Posts: 70
|
Posted: Fri Sep 09, 2005 6:53 pm |
Lol its ok, thanks. i used the code i had before, the extra time it takes to enter the extra variables is more than made up for with the time the code saves.
On a related matter, ive tried to translate it for another alias, but not sure where im going wrong:
| Code: |
#loop @toxins {
harvest %2 %3 %4
#alarm +2 {
outflask syrup
blend %2 with syrup
}
#alarm +2 {inkit %2}
}
toxins = 0 |
the alarms are because i have to wait before it can complete the next section, so i want it to run through all that, waiting for the desired time before moving onto the next, and looping once it has completed it. |
|
|
|
 |
charneus Wizard

Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Fri Sep 09, 2005 7:09 pm |
What does it do that makes it not work? Does it bypass the alarms and go directly to the next command?
I'm sure a lot of people would disagree with me on this, but I find that the #WAIT command has never really given me a problem. So, why not try using #WAIT 2000 in place of the alarms?
If that's not the problem, then what is it doing? And you do have the alias set up to #VAR toxins %1?
Fill me in on what's going on... :P Can't just say "It's going wrong." and leave us guessing! :)
Charneus |
|
|
|
 |
Fergal1982 Wanderer
Joined: 08 Aug 2005 Posts: 70
|
Posted: Fri Sep 09, 2005 7:13 pm |
lol sorry. meant to type more, but forgot. its skipping to the next lot of commands straight away. then firing off the commands after the alarm after the delay.
I tried #wait 2000 but i just got a syntax error.
i do have #var toxins %1 set. |
|
|
|
 |
charneus Wizard

Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Fri Sep 09, 2005 7:25 pm |
Ok... with the #WAIT command, this is what it would look like:
| Code: |
#loop @toxins {
harvest %2 %3 %4
#wait 2000
outflask syrup
blend %2 with syrup
#wait 2000
inkit %2
}
toxins = 0 |
Or, for the trigger line:
| Code: |
| First part of command here {#loop @toxins {harvest %2 %3 %4;#wait 2000;outflask syrup;blend %2 with syrup;#wait 2000;inkit %2};toxins = 0 |
Hope this works for you.
Charneus |
|
|
|
 |
Fergal1982 Wanderer
Joined: 08 Aug 2005 Posts: 70
|
Posted: Fri Sep 09, 2005 7:36 pm |
worked a charm. thanks. out of interest, how do you cancel an alias like this when it is in full swing?
|
|
|
|
 |
charneus Wizard

Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Fri Sep 09, 2005 7:39 pm |
You're welcome. As for cancelling it, not -totally- sure. Normally, I just turn off parsing for a couple of seconds. (shrugs) Give it a try and see if it works. :)
Charneus |
|
|
|
 |
Vijilante SubAdmin

Joined: 18 Nov 2001 Posts: 5187
|
Posted: Fri Sep 09, 2005 9:00 pm |
On the original buy issue, it looks like you are on Achaea or another Iron Realms mud. Looking at the help for buy it supports an arguement for how many to buy. So you can simply insert the proper number assuming the shop has that many.
In your other script I wouldn't reccommend the use of #WAIT since you become locked in to that delay. The correct way to do this is with a recursive alias that is called from your alarm. In this case you need two delays, so 2 alarms and you have to either nest them or create cumulative times for them. I would suggest that this would be better handled by triggers then using a fixed time. I have seen rather large variances in how long it takes to recover balance from many simple activities, and would expect the same behavior to continue through all sorts of activities. The benefits of using this design is that you simply 0 the single control variable to break the loop; when doing so the loop will still finish out its sequence though. I find this a better exit then any other form.
| Code: |
#ALIAS AHarvest {
#if (@toxins) {
harvest %2 %3 %4
#ALARM {+2} {outflask syrup ;blend %2 with syrup}
#ALARM {+4} {inkit %2;AHarvest}
#ADD toxins -1
}
} |
|
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
 |
Fergal1982 Wanderer
Joined: 08 Aug 2005 Posts: 70
|
Posted: Fri Sep 09, 2005 10:17 pm |
I tried pasting in the code you listed above vijilante, but this didnt seem to work (using the command 'aharvest 2 camas')
Im actually on Akanbar (still in Beta - but very good!)
Thanks
Fergal |
|
|
|
 |
|
|
|