[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Super Basic Math Issue
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Super Basic Math Issue

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


Posted by Magellan   (10 posts)  [Biography] 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.
[Go to top] top

Posted by Magellan   (10 posts)  [Biography] bio
Date Reply #1 on Mon 26 Jun 2017 04:25 AM (UTC)
Message
SetVariable ("Variable", "@Variable"+1)


i knew it was simple.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] 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
[Go to top] top

Posted by Fiendish   USA  (1,641 posts)  [Biography] 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
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] 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
[Go to top] 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.


1,364 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]