Calling an Alias from an Alias

Posted by Boca on Thu 19 Jul 2001 10:10 PM — 9 posts, 36,865 views.

#0
Why can't I call an Alias in another alias?

Here is the first: alias lb
send look at board
and it works fine.

The second: alias grid
send goto 3070
lb
this will take me to the right room, but lb is not being translated to "look at board".

What am I doing wrong?

Thanks,
Boca

Here is the second: grid
Australia Forum Administrator #1
I didn't want to make aliases recursive (one alias call another for a couple of reasons):

  • If you rename the 'lb' alias then the other one ('grid') will stop working, maybe unexpectedly
  • The whole idea of aliases is to let you type things quickly in the heat of the moment. However when you are setting up the alias you hopefully have got more time on your hands, so you can just type the word in full. It also makes it easier to see what the alias does.
#2
I like the idea of having aliases being able to call each other. Perhaps there could be a special escape character...like the @ before a variable used in an alias or trigger?

It could be useful if you had a common activity that you used both singly and in another activity.

For instance, on a mud I play, sometimes I often have to dual my "default weapon", using an alias like this:

dwp
sec @second

But I also use area portals, which requires switching items around:

useportal *
hold %1
enter
dwp

and...there could be more, but this is the third I came up with:
useam
hold amulet
enter
dwp

If I wanted to add addition stuff to my "dwp" alias, I'd only have to change it in the one place. Without the ability to call aliases from aliases, I'd either have to script something, or change it at least three times. Changing it in three places is kind of ugly. :)

Anyway, just some thoughts.
Australia Forum Administrator #3
It is on my list of things to do. :)
#4
I've looked for this topic in more recent posts and the release notes, so pardon me if I've missed this.

I think this would be a valuable feature. I have combat scripts that work on the basis of aliases being resuable "chunks" of actions. Like in my world, I have to fill pipes, light pipes and empty pipes, as well have a trigger for lighting a pipe when it goes out. Usually, when I fill a pipe, I would like to light it. Rather than copy code from the light pipe alias, and have 2 sets of code to maintain, I would rather have my fill pipe alias call the light pipe alias.

Any ideas on how I could do this easily, if we can't have alias's call each other?

Regards...
Canada #5
The standard way to currently do what you want is to call scripts. You don't have to be a super-talented programmer to write very simple stuff like this.


Sub Light_Pipe (AliasName, AliasLine, arrWildcards)
  World.Send "light pipe"
End Sub

Sub Refill_Pipe (TriggerName, TriggerLine, arrWildcards)
  World.Send "empty pipe"
  World.Send "fill pipe with tobacco"
  Light_Pipe TriggerName, TriggerLine, arrWildcards  'We are calling the "Light_Pipe" subroutine which expects 3 arguments.
End Sub

The last line of the subroutine "Refill_Pipe" calls the "Light_Pipe" subroutine.

Now, if you want to perform a batch of actions from several places (IE: Aliases and Triggers), then you simply call the same subroutine from those various sources.

The above example uses VisualBasicScript, which in my opinion is the easiest to learn.
Australia Forum Administrator #6
Quote:

Any ideas on how I could do this easily, if we can't have alias's call each other?


My standard suggestion here is to use variable expansion. eg.

Have a variable "lightpipe" which does what you need to light it, eg.

"lightpipe" =
get match
light match
put match to pipe
breath deeply

(or whatever)

Then in your "lightpipe" alias just do this:

@lightpipe

Make sure you check "expand variables".

Then in your "fillpipe" alias, do your stuff to fill the pipe, and on the last line:

@lightpipe

Now if you ever need to change how the pipe is lit you just change one spot - the variable.
#7
i dont know if execute was not present when this question was asked but i see you can achieve this using
world.

Execute ("alias1")
Execute ("alias2")

etc.

USA #8
Execute was added in v3.35, which was released in 2003. The latest version at the time this thread began was v3.15. :)