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 Basic Math Issue

Super Basic Math Issue

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


Posted by Magellan   (15 posts)  Bio
Date Mon 26 Jun 2017 03:00 AM (UTC)
Message
getting frustrated here. i'm new to mushclient, and have exclusively used zmud for close to (holy crap) 20 years. in zmud what i would do is #math @variable+1 and get the results i want.

Basically what i need is the likely super basic coding for how to add 1 to a variable.

EVENT 1: Variable+1
EVENT 2: Variable+1
EVENT 3: Variable-1

each event would be it's own separate trigger.

I've been searching the forum's and can't seem to find a topic that mirrors what i need enough for me to understand fully what i need to do to implement it. Thanks in advance.
Top

Posted by Magellan   (15 posts)  Bio
Date Reply #1 on Mon 26 Jun 2017 04:25 AM (UTC)
Message
SetVariable ("Variable", "@Variable"+1)


i knew it was simple.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #2 on Mon 26 Jun 2017 04:39 AM (UTC)
Message
An alternative is to get the variable, convert it to a number, and add 1, like this:


SetVariable ("foo", tonumber (GetVariable ("foo")) + 1)


Your method of expanding the variable like @foo won't work if you have changed that variable in the same trigger, because substitution of variables is done before the script starts running.

- Nick Gammon

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

Posted by Fiendish   USA  (2,534 posts)  Bio   Global Moderator
Date Reply #3 on Mon 26 Jun 2017 07:23 AM (UTC)
Message
Quote:
substitution of variables is done before the script starts running.

Pre-process substitution is something that some of us have kinda internalized over the years, but is there a document describing when different bits of a script happen (immediate send block vs script function call vs @variable expansion vs xml processing, etc)? If not I think I'll put one together.

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #4 on Mon 26 Jun 2017 10:19 PM (UTC)

Amended on Mon 26 Jun 2017 10:20 PM (UTC) by Nick Gammon

Message
I did a video about using variables:

http://www.gammon.com.au/forum/?id=10863

If you just want to add one to a variable in this session (rather than to be remembered forever) then it is simpler to use Lua variables. For example:


-- make sure variable exists initially
if mobsKilled == nil then
  mobsKilled = 0
end -- if

mobsKilled = mobsKilled + 1


You can do that in "send to script" in a trigger, with Lua as the scripting language.

Alternatively (although it is a bit more obscure):


mobsKilled = (mobsKilled or 0) + 1

- 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,067 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.