Gammon Forum
Entire forum
MUSHclient
Lua
help with adding and subtracting in triggers and aliases
help with adding and subtracting in triggers and aliases
|
It is now over 60 days since the last post. This thread is closed.
  Refresh page
Posted by
| FishOnSpeed
USA (31 posts) bio
|
Date
| Wed 12 Dec 2007 05:13 PM (UTC) |
Message
| i need to be able to do math inside some triggers and aliases.
im not sure how to do it but all i need right now is A+1=b
and A-C=D kinda stuff where b and d get stored in variables
|
~FishOnSpeed | top |
|
Posted by
| Nick Gammon
Australia (22,973 posts) bio
Forum Administrator |
Date
| Reply #1 on Wed 12 Dec 2007 07:47 PM (UTC) |
Message
| See http://www.mushclient.com/faq point 31.
Also look at some of the posts in the Lua section, a lot have examples that do arithmetic. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
Posted by
| FishOnSpeed
USA (31 posts) bio
|
Date
| Reply #2 on Thu 13 Dec 2007 06:52 PM (UTC) |
Message
| thank you that helped with one of my problems.
i looked through the faq and i didnt see anything to help me with this one.
<aliases>
<alias
match="print"
enabled="y"
variable="diffvnum"
send_to="9"
sequence="100"
>
<send>diffvnm = minvnum - maxvnum </send>
</alias>
</aliases>
i put the alias in and i want it to get the difference of the two numbers.
<variables>
<variable name="diffvnum">diffvnm = minvnum - maxvnum </variable>
</variables>
but i get this instead. |
~FishOnSpeed | top |
|
Posted by
| Nick Gammon
Australia (22,973 posts) bio
Forum Administrator |
Date
| Reply #3 on Fri 14 Dec 2007 03:08 AM (UTC) |
Message
| It is doing what you told it to, setting the variable "diffvnum" to be the text "diffvnm = minvnum - maxvnum".
To do calculations you need to "send to script", like this:
<aliases>
<alias
match="print"
enabled="y"
send_to="12"
sequence="100"
>
<send>
print ("difference is ", minvnum - maxvnum)
</send>
</alias>
</aliases>
This is displaying the difference between two script variables (not two MUSHclient variables).
If you try this alias you will get an error if the variables don't exist, because you are subtracting non-existent quantities.
If you want to use MUSHclient variables, a simple way is to use the "var" script, which modifies the example slightly:
<aliases>
<alias
match="print"
enabled="y"
send_to="12"
sequence="100"
>
<send>
require "var"
print ("difference is ", var.minvnum - var.maxvnum)
</send>
</alias>
</aliases>
If you simply want to store the difference as another variable, then you simply assign the result, like this:
<aliases>
<alias
match="print"
enabled="y"
send_to="12"
sequence="100"
>
<send>
require "var"
var.diffvnum = var.minvnum - var.maxvnum
</send>
</alias>
</aliases>
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
Posted by
| FishOnSpeed
USA (31 posts) bio
|
Date
| Reply #4 on Fri 14 Dec 2007 05:02 PM (UTC) |
Message
| That worked perfectly.
Thank you very much. |
~FishOnSpeed | 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.
13,249 views.
It is now over 60 days since the last post. This thread is closed.
  Refresh page
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.