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 ➜ Lua ➜ Complex math within an alias

Complex math within an alias

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


Posted by Aralia Faal   (25 posts)  Bio
Date Wed 10 Oct 2012 04:45 AM (UTC)
Message
Alright so I want to make an alias that takes two variables, @strength and @constitution, and adds them together then divides that by 10 then divides that by 2. Once the math is done it would SendImmediate (train %1 ##). Where ## is the outcome of the math.

I tried doing this on my own, starting with:

bc.digits (20)
n = bc.number (((@strength + @constitution) / 10) / 2)
print(n)

Witch worked so I changed print(n) to SendImeediate(n) which also worked. But the moment I tried adding anything before the n within the ( ) it failed.

Could I please get some help?
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Wed 10 Oct 2012 05:49 AM (UTC)
Message
Please show the whole thing:

Template:copying For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.

- Nick Gammon

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

Posted by Aralia Faal   (25 posts)  Bio
Date Reply #2 on Wed 10 Oct 2012 06:12 AM (UTC)

Amended on Wed 10 Oct 2012 01:47 PM (UTC) by Aralia Faal

Message
The capture trigger:


<aliases>
  <alias
   match="train *"
   enabled="y"
   expand_variables="y"
   send_to="12"
   sequence="100"
  >
  <send>bc.digits (20)
n = bc.number (((@strength + @constitution) / 10) / 2)
SendImmediate(n)</send>
  </alias>
</aliases>


The Variable:


<variables>
  <variable name="Constitution">578</variable>
</variables>

<variables>
  <variable name="Strength">496</variable>
</variables>
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #3 on Wed 10 Oct 2012 08:24 AM (UTC)
Message
Why are you using bc? That is for, like, hundreds of digits of precision.

- Nick Gammon

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

Posted by Fiendish   USA  (2,534 posts)  Bio   Global Moderator
Date Reply #4 on Wed 10 Oct 2012 12:55 PM (UTC)
Message
Quote:
the moment I tried adding anything before the n within the ( ) it failed.

Please show what you tried doing that failed.

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

Posted by Aralia Faal   (25 posts)  Bio
Date Reply #5 on Wed 10 Oct 2012 02:01 PM (UTC)
Message
Nick Gammon said:

Why are you using bc? That is for, like, hundreds of digits of precision.


Because I'm not all that good with the functions and it was the first thing I found that began to work for what I wanted.

Fiendish said:

Quote:
the moment I tried adding anything before the n within the ( ) it failed.

Please show what you tried doing that failed.


I first started with what I wanted it to be:

<aliases>
  <alias
   match="train *"
   enabled="y"
   expand_variables="y"
   send_to="12"
   sequence="100"
  >
  <send>bc.digits (20)
n = bc.number (((@strength + @constitution) / 10) / 2)
SendImmediate(train %1 (n))</send>
  </alias>
</aliases>


I got the error:

Error number: 0
Event: Compile error
Description: [string "Alias: "]:3: ')' expected near 'str'
Called by: Immediate execution

I removed the %1 for now, using str, to see if I could get the "n" to work. But it just sends "train str (n)" exactly as it is.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #6 on Wed 10 Oct 2012 08:50 PM (UTC)
Message
It would be more like:


Send ("train %1 " .. n)


One is a literal, one is a variable.





bc.digits (20)
n = bc.number (((@strength + @constitution) / 10) / 2)


can be just:


n = ((@strength + @constitution) / 10) / 2)

- Nick Gammon

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

Posted by Aralia Faal   (25 posts)  Bio
Date Reply #7 on Wed 10 Oct 2012 10:13 PM (UTC)
Message
Awsome! Can always count on you.

Is there a way to make it round up to the next whole number?
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #8 on Thu 11 Oct 2012 02:58 AM (UTC)
Message
http://www.gammon.com.au/modules

Inside commas.lua is a round function.

eg.


require "commas"

n = round (n)


- Nick Gammon

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

Posted by Aralia Faal   (25 posts)  Bio
Date Reply #9 on Thu 11 Oct 2012 03:05 AM (UTC)
Message
Thanks. You are a big help, as always.
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.


25,867 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.