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
➜ Simple subtraction, I'm stumped.
|
Simple subtraction, I'm stumped.
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Nexas
(5 posts) Bio
|
| Date
| Sat 24 Nov 2007 01:48 AM (UTC) |
| Message
| | I play on Achaea and I'm trying to make a fairly simple but tedious alias. I have two triggers that set variables for "Full health" and "Current health" what I need to do now is figure out a way to set a variable for the difference of the two. My scripting is in Lua, but I'm not sure if this would be a Lua or MUSHclient command. Any help would be great, thanks! | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Sat 24 Nov 2007 02:49 AM (UTC) |
| Message
| |
| Posted by
| Nexas
(5 posts) Bio
|
| Date
| Reply #2 on Sat 24 Nov 2007 02:57 AM (UTC) |
| Message
| | I looked through that a little bit. But what I need is something like Print (5 - 4) --> 1 except I need 1 to be set as the variable content, and I'm not sure how to do that. | | Top |
|
| Posted by
| Nexas
(5 posts) Bio
|
| Date
| Reply #3 on Sat 24 Nov 2007 06:11 AM (UTC) |
| Message
| local crh = tonumber(GetVariable("crh"))
local health = tonumber(GetVariable("health"))
local diffh = health - crh
This is what I have so far, I need another line that can either change the diffh variable into a MUSH variable so I can retrieve the number. Or a line that could send the number directly to the game, but not as a print or note. | | Top |
|
| Posted by
| Nexas
(5 posts) Bio
|
| Date
| Reply #4 on Sat 24 Nov 2007 02:18 PM (UTC) |
| Message
| I think I figured out that I need to serialize the variable? But I'm not totally sure how I do that. I looked at this post http://www.gammon.com.au/forum/?id=4960, which probably is obvious to anyone who knows much about coding, heh. I'm just not sure what all I need to do to serialize this one variable?
Or if there's an easier/more obvious way to do this, I'll take that suggestion too! | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #5 on Sat 24 Nov 2007 06:58 PM (UTC) |
| Message
| It isn't as complicated as all that. Lua knows that if you try to subtract two things they must be numbers, so you don't need "tonumber". First, look at this:
print (GetVariable ("crh") - GetVariable ("health"))
That prints the difference.
You can also use the "var" module to make a pseudo-table that lets you access MUSHclient variables easily:
require "var"
print (var.crh - var.health)
Quote:
I need another line that can either change the diffh variable into a MUSH variable so I can retrieve the number.
You don't really need that unless you want it for some reason, but this is how you could do it:
require "var"
diffh = var.crh - var.health -- Lua variable diffh
var.diffh = diffh -- MUSHclient variable diffh
Quote:
Or a line that could send the number directly to the game, but not as a print or note.
Just use "Send", like this:
require "var"
Send ("say My health has changed by " .. var.crh - var.health)
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Nexas
(5 posts) Bio
|
| Date
| Reply #6 on Sat 24 Nov 2007 08:32 PM (UTC) |
| Message
| | It works! Thank you so much! I spent a lot of time figuring out the wrong things, hehe. | | 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.
24,925 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top