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
➜ General
➜ Comparison breaking because of low number?
Comparison breaking because of low number?
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Faedara
(106 posts) Bio
|
Date
| Mon 22 Nov 2010 01:55 PM (UTC) |
Message
| This is my timer as it is now:
<timers>
<timer enabled="y" second="0.10" offset_second="0.00" send_to="12"
group="AutoSipperAlpha" >
<send>if GetVariable ("sip_hp") > GetVariable ("cur_hp") and GetVariable ("sip_bal") == "1" then
Send ("Sip Health")
SetVariable ("sip_bal", "0.5")
EnableTimer ("sip_bal_check", true)
end</send>
</timer>
</timers>
This is the set of variables it's currently using:
sip_hp = 1512.8
cur_hp = (1-1891)
This system works perfectly fine until cur_hp drops below 1000. Is there a reason for this, and is there a workaround? Or am I missing an entirely different problem. Also, does anyone here know how I would get into the MUSH clan on Achaea? |
The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2. | Top |
|
Posted by
| Faedara
(106 posts) Bio
|
Date
| Reply #1 on Mon 22 Nov 2010 02:03 PM (UTC) |
Message
| Additional notes: the timer starts working again as soon as health is back over 1000
And yes, I'm that girl you all love to hate. I think I'm setting the record for most annoying questions/problems/failures on the front page at one time. |
The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2. | Top |
|
Posted by
| Seriley
(42 posts) Bio
|
Date
| Reply #2 on Mon 22 Nov 2010 06:42 PM (UTC) |
Message
| I think you are comparing strings not numbers.
If you are using Lua, just do tonumber(GetVar.....) > tonumber(GetVar.....)
| Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #3 on Mon 22 Nov 2010 08:35 PM (UTC) |
Message
|
Faedara said:
And yes, I'm that girl you all love to hate. I think I'm setting the record for most annoying questions/problems/failures on the front page at one time.
Not at all. It is great to see intelligent questions asked, it shows you are attempting to solve your own problems (which is more than some people do). You also post enough code, and explain the problem, to assist in helping you. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #4 on Mon 22 Nov 2010 08:38 PM (UTC) |
Message
| Anyway, I agree with Seriley - string comparisons give strange results with numbers. For example:
print ("1000" < "900") --> true
For fleeting variables (your HP change all the time, right?) you hardly need MUSHclient variables. Use Lua variables, which can hold numbers.
In another post I did a tonumber on the ATCP variables, so then stick with the Lua version.
For example:
hp, max_hp = tonumber (stats.health), tonumber (stats.maxhealth)
OK, just use hp and max_hp - no need to make things harder by turning them into MUSHclient variables with SetVariable, and then turning them back with GetVariable, and then doing a tonumber on them. Why go through all the pain? |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #5 on Mon 22 Nov 2010 08:39 PM (UTC) |
Message
| I can't find anything else particularly wrong here, so I think Seriley has it. Here's a helper function you can add to your script file (or into a plugin's script section) to make it slightly more obvious:
function GetNumericVariable(name)
return tonumber(GetVariable(name))
end
Faedara said: Also, does anyone here know how I would get into the MUSH clan on Achaea?
Sure, poke me (if I'm actually online) or anyone in the CLHELP MUSH clan scroll. If your Achaea name is different from here, it would help to say what it is so we can look for you too. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| Faedara
(106 posts) Bio
|
Date
| Reply #6 on Mon 22 Nov 2010 09:23 PM (UTC) |
Message
| Alright, in that order...
Thanks Seriley, I'll post again if that fixes the problem. I forget that Variables aren't exactly what you put into them.
Thanks Nick, I do try my best to understand what I'm doing, I feel it's better to ask a hundred questions and move a step at a time than take a hundred steps and then whine about how nothing worked and I have to start from the beginning.
Lua variable would only work for one of those number variables I need to have (cur_hp), because (max_hp), (sip_hp), and (sip_per) should save over closing the client. Imagine logging in and you're suddenly in the middle of a fight, but your AutoSipper no longer has your variables, so you have to manually heal and fight when you got the Sipper to avoid such situations.
Also, this is the Alpha version of my sipper, so nothing is in Script yet. In fact, it's all triggers and timers right now. I need to build a stable working version based on what I know before I build this scripted version based on what I'm learning.
Thank you all for the help, I'm going back to work on it. |
The eternally clueless <3
Currently looking for a mentor/tutor to help me learn everything about Lua from the ground up. I can't understand 28*41 until I learn what causes 2+2. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #7 on Mon 22 Nov 2010 09:37 PM (UTC) |
Message
|
Faedara said:
Imagine logging in and you're suddenly in the middle of a fight, but your AutoSipper no longer has your variables, so you have to manually heal and fight when you got the Sipper to avoid such situations.
Well that is exactly why you serialize your Lua variables at world open, and world save.
On world startup, you convert your saved MUSHclient variables into Lua variables. At world save, you convert them back so they are saved for next time. Meanwhile, for the hours in-between you have the flexibility of using Lua variables. The serialization process described in that thread keeps the "type" of the variables, so a Lua number stays a number. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | 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.
26,064 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top