help with adding and subtracting in triggers and aliases

Posted by FishOnSpeed on Wed 12 Dec 2007 05:13 PM — 5 posts, 20,716 views.

USA #0
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
Australia Forum Administrator #1
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.
USA #2
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.
Australia Forum Administrator #3
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>


USA #4
That worked perfectly.
Thank you very much.