Gammon Forum
Entire forum
MUSHclient
General
comparing two variables with a value over 100
comparing two variables with a value over 100
|
It is now over 60 days since the last post. This thread is closed.
  Refresh page
Posted by
| Guy Styles
(4 posts) bio
|
Date
| Wed 28 Aug 2002 06:25 PM (UTC) |
Message
| I run a script called autoheal. I pull the value HP off of my prompt.
Sub Auto_Heal (AliasName, TriggerLine, arrWildcards)
Dim Health
Dim LowHealth
LowHealth = world.getvariable ("lowHP")
Health = world.getvariable ("hp")
If Health < LowHealth Then
World.Note "HP: " & World.GetVariable("HP")
World.Send "cast " & World.GetVariable ("Vigspell")
End IF
End Sub
Let's say the lowhp is set to 50
My script works fine, but if my HP are 100 or over, then I cast.
I can't figure out why. | top |
|
Posted by
| Nick Gammon
Australia (22,975 posts) bio
Forum Administrator |
Date
| Reply #1 on Wed 28 Aug 2002 09:02 PM (UTC) |
Message
| It is comparing them as strings (which is how variables are stored), thus "20" is higher - as a string - than "120", because the first character has precedence.
You need this:
LowHealth = CInt (world.getvariable ("lowHP"))
Health = CInt (world.getvariable ("hp"))
CInt is "Convert to Integer". |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
Posted by
| Guy Styles
(4 posts) bio
|
Date
| Reply #2 on Wed 28 Aug 2002 09:22 PM (UTC) |
Message
| Ahh. heck yeah!
Thanks Nick Gammon! | top |
|
Posted by
| Shadowfyr
USA (1,786 posts) bio
|
Date
| Reply #3 on Wed 28 Aug 2002 11:10 PM (UTC) |
Message
| Aliases and timers use a different number of call arguements. Aliases use name, output and wildcards, while timers only have the name.
To do this you can simply make a new sub like:
sub timed_autoheal(timername)
call Auto_Heal("","","")
end sub
In general if you are not using the wildcard or output fields from a call and you know you will be using it from a timer, etc., you should place the code in a seperate sub like:
sub alias_AH (AliasName, TriggerLine, arrWildcards)
call Auto_Heal
end sub
sub timer_AH (TimerName)
call Auto_Heal
end sub
Sub Auto_Heal
Dim Health
Dim LowHealth
LowHealth = CInt (world.getvariable ("lowHP"))
Health = CInt (world.getvariable ("hp"))
If Health < LowHealth Then
World.Send "cast " & World.GetVariable ("Vigspell")
End If
End Sub
Or at least that is what I would do in such a case. ;) | top |
|
Posted by
| Magnum
Canada (580 posts) bio
|
Date
| Reply #4 on Thu 29 Aug 2002 06:34 AM (UTC) |
Message
| Magnum gives Shadowfyr a Potion of Cure Confusion.
Where did timers come into play? :) |
Get my plugins here: http://www.magnumsworld.com/muds/
Constantly proving I don't know what I am doing...
Magnum. | top |
|
Posted by
| Nick Gammon
Australia (22,975 posts) bio
Forum Administrator |
Date
| Reply #5 on Thu 29 Aug 2002 06:46 AM (UTC) |
Message
| I was wondering that too, but thought it best to say nothing, as perhaps I was 'skimming' again. ;) |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
Posted by
| Shadowfyr
USA (1,786 posts) bio
|
Date
| Reply #6 on Thu 29 Aug 2002 07:40 AM (UTC) |
Message
| I am not confused.. There was definitely a mention of adding a second thing that was timed in there. I can only assume he deleted the post that asked about it some time between, around or when I was posting it.
Specifically, he asked why trying to call the same routine from a timer was causing it to fail with 'wrong number of arguements'.
Now as to why the post isn't there now... That I am confused about. lol | top |
|
Posted by
| Nick Gammon
Australia (22,975 posts) bio
Forum Administrator |
Date
| Reply #7 on Thu 29 Aug 2002 08:17 AM (UTC) |
Message
| Hey, is it April 1st?
That is a good idea, make a post asking a complex question, wait for someone to reply, change or delete the post, and then get someone to comment that they are confused. :P |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
Posted by
| Guy Styles
(4 posts) bio
|
Date
| Reply #8 on Thu 29 Aug 2002 07:29 PM (UTC) |
Message
| Yes, I did post a question about complex timers and yadda yadda yadda. Although, I figured it out about 30min. later and deleted the post, but amazingly shadowfyr was very quick to the response, and I am glad he was because he clarified some things I hadn't thought of yet.
Thanks Guys. | 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.
19,259 views.
It is now over 60 days since the last post. This thread is closed.
  Refresh page
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.