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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  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] Refresh page


Posted by FishOnSpeed   USA  (31 posts)  [Biography] 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
[Go to top] top

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

Posted by FishOnSpeed   USA  (31 posts)  [Biography] 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
[Go to top] top

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

Posted by FishOnSpeed   USA  (31 posts)  [Biography] bio
Date Reply #4 on Fri 14 Dec 2007 05:02 PM (UTC)
Message
That worked perfectly.
Thank you very much.

~FishOnSpeed
[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.


13,249 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 HostDash]