Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ A simple alias to set a variable

A simple alias to set a variable

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Unregistered user   (72 posts)  Bio
Date Wed 02 Aug 2000 (UTC)
Message
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
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Wed 02 Aug 2000 05:31 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Unregistered user   (72 posts)  Bio
Date Reply #2 on Wed 02 Aug 2000 09:26 AM (UTC)
Message
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
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #3 on Thu 03 Aug 2000 (UTC)
Message
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"?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Unregistered user   (72 posts)  Bio
Date Reply #4 on Thu 03 Aug 2000 09:41 AM (UTC)
Message
> 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
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #5 on Fri 04 Aug 2000 (UTC)
Message
> 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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


17,969 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.