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 ➜ Super simple question about performing arithmetic in aliases

Super simple question about performing arithmetic in aliases

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


Posted by Tetnao   (8 posts)  Bio
Date Wed 13 Oct 2010 10:53 AM (UTC)
Message
I have a variable called 'level', a trigger which triggers on my level message to update my own level into 'level' variable.

I would like to make an alias that checks who is within 20 levels of me, and my mud provides the command as

who level <lower level> <higher level>

I have seen one of nick's youtube videos on how to expand a variable in an alias to get it's content, however, i cant figure out how to perform an arithmetic operation with the value.

Here's what I did:

who level @level - 20 @level + 20


Lets say my level is 46, it simply sends "who level 46 - 20 46 + 20"

How can I perform arithmetic operations on the variable then send them?

Thanks!
Top

Posted by Bobo   USA  (16 posts)  Bio
Date Reply #1 on Wed 13 Oct 2010 03:17 PM (UTC)

Amended on Wed 13 Oct 2010 03:18 PM (UTC) by Bobo

Message
If it were me, I'd use a scripting language to do this, I'm not familiar with manipulating an @variable in MUSH (though I know you can do it with z/CMUD, because of their built-in and generally automatic scripting language) so I can't answer that question, but maybe I can help somewhat.

A simple example in JScript -- my preferred language -- would look something like this:

var level = Number(world.GetVariable("level")) ;

world.Send("who level " + (level-20) + " " + (level + 20) ) ;


If you're not using a scripting language at the moment, you can switch to JScript and use that -- be sure to enable "Send to Script" in the alias menu.

Bleh!
Top

Posted by LezChap   (36 posts)  Bio
Date Reply #2 on Wed 13 Oct 2010 07:11 PM (UTC)

Amended on Wed 13 Oct 2010 07:12 PM (UTC) by LezChap

Message
Make an Alias for whatever you want it to be (ie: wholevel)

In the alias, make it send to script, and under Lua, it'd be something like:

Send("who level " .. (GetVariable("level") - 20) .. " " .. (GetVariable("level") + 20))

I don't think merely using "level" in the Javascript example will retrieve a MUSHclient variable...only a variable set in the Javascript. At least that's the way I understand it.

You may be able to get away with using @level, but by using the GetVariable script function, you're retrieving it at that moment (in case it just got modified in another alias/trigger/whatever that may call your wholevel alias in the future).
Top

Posted by Bobo   USA  (16 posts)  Bio
Date Reply #3 on Thu 14 Oct 2010 02:24 AM (UTC)
Message
LezChap said:

I don't think merely using "level" in the Javascript example will retrieve a MUSHclient variable...only a variable set in the Javascript. At least that's the way I understand it.


Yeah, hence the var level = ... declaration. If you wanted to make it one line in JScript it'd be more like:

 world.Send("who level " + (Number(world.GetVariable("level"))-20) + " " + (Number(world.GetVariable("level"))+20)) ; 


I always use the Number() function in JScript when dealing with numeric global variables because, I think, either MUSHClient or JScript has them set as "string" variables.

Bleh!
Top

Posted by Tetnao   (8 posts)  Bio
Date Reply #4 on Thu 14 Oct 2010 03:52 AM (UTC)
Message
Thanks for help guys, this is solved :)
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #5 on Thu 14 Oct 2010 04:22 AM (UTC)
Message
Bobo said:
I always use the Number() function in JScript when dealing with numeric global variables because, I think, either MUSHClient or JScript has them set as "string" variables.

MUSHclient GetVariable/SetVariable variables are strings, yes. If something like SetVariable("foo", 4) works, it's because the 4 is coerced into "4" by JScript.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by LezChap   (36 posts)  Bio
Date Reply #6 on Thu 14 Oct 2010 04:23 AM (UTC)
Message
Bobo said:

LezChap said:

I don't think merely using "level" in the Javascript example will retrieve a MUSHclient variable...only a variable set in the Javascript. At least that's the way I understand it.


Yeah, hence the var level = ... declaration. If you wanted to make it one line in JScript it'd be more like:

 world.Send("who level " + (Number(world.GetVariable("level"))-20) + " " + (Number(world.GetVariable("level"))+20)) ; 


I always use the Number() function in JScript when dealing with numeric global variables because, I think, either MUSHClient or JScript has them set as "string" variables.


I missed that first line the first time I read the code... And the Number() function (or tonumber() in Lua) is a very good point...
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.


20,091 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.