A simple alias to set a variable

Posted by Unregistered user on Wed 02 Aug 2000 12:00 AM — 6 posts, 23,666 views.

#0
Can someone tell me how to create an alias to set a variable?

Eg. typing
setBuffer MrTank
would set the value of variable "buffer" to "MrTank".

This doesn't work:
world.addAlias(
"setBuffer",
"sb (.+)", "",
eEnabled | eAliasRegExp, "set" );

function set( id, output, wildcards ) {
wildcards = VBArray( wildcards ).toArray();
world.setVariable( "buffer", wildcards[ 0 ] );
world.note( "buffer: '" + wildcards[ 0 ] + "'" );
return;
}

- skj
Australia Forum Administrator #1
I tried your example and it did work, after I defined eEnabled and eAliasRegExp.

I also added the "script prefix" to add the alias, like this:



/world.addAlias("setBuffer", "sb (.+)", "", 129, "set" );



The number 129 is what you get if you add eEnabled (1) and eAliasRegExp (128).

Used in conjunction with the script routine you specified, added to the script file, if you type:

sb MrTank

... then it works.

Note that I am typing "sb" and not "setBuffer". "sb" is what you have specified in the alias to "match on". The word "setBuffer" is the label of the alias.
#2
All the code in my previous post is in my script file. The alias is added in a function which is called upon opening of the world to which the script is associated. The flags are defined (otherwise there would be an error, no?) with correct values.

- skj
Australia Forum Administrator #3
Why bother adding the alias on world open? Once the alias is added, it is there for good.

It is easier anyway to add an alias using the GUI interface - just bring up the configuration screen for the world, select "aliases" and click on "add".

You haven't said in what way it doesn't work. Has the alias in fact been added (use the GUI interface to check)? Does it not detect your typing of "sb blah"?
#4
> Why bother adding the alias on world open? Once the
> alias is added, it is there for good.

I prefer to do everything in the script because then it is a lot easier to upgrade the client when you don't have to redefine or save and load triggers and aliases. I also like to have all the alias/trigger definitions and functions in one place.

> It is easier anyway to add an alias using the GUI
> interface - just bring up the configuration screen
> for the world, select "aliases" and click on "add".

That's a matter of personal preferense. I'd rather edit a text file than use a GUI to configure a program. But that's just me *grin*

> You haven't said in what way it doesn't work. Has
> the alias in fact been added (use the GUI interface
> to check)? Does it not detect your typing of "sb
> blah"?

When I type "sb foo" in the input window, nothing happens. No note is displayed in the output window, and the variable "buffer" isn't created.

- skj
Australia Forum Administrator #5
> I prefer to do everything in the script because
> then it is a lot easier to upgrade the client
> when you don't have to redefine or save and
> load triggers and aliases. I also like to have
> all the alias/trigger definitions and functions in one place.

Fair enough, however when you upgrade the client the aliases and triggers are automatically upgraded as well.

>When I type "sb foo" in the input window,
>nothing happens. No note is displayed in
>the output window, and the variable "buffer"
>isn't created.

This is strange. When you say "nothing happens" I presume you mean you don't get an error message from the MUD.

In that case, it sounds like the alias is matching, but the script isn't being called.

Can you confirm that your script line *does* in fact create the alias, and that the flags, and script name are all there? At least that will rule out the possibility that it is failing for some reason.

One possibility is that an earlier alias which matches the "sb" is still there. Once an alias is created the script will not replace it, unless you also use "eReplace" as a flag.