comparing two variables with a value over 100

Posted by Guy Styles on Wed 28 Aug 2002 06:25 PM — 9 posts, 30,959 views.

#0
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.
Australia Forum Administrator #1
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".
#2
Ahh. heck yeah!
Thanks Nick Gammon!
USA #3
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. ;)
Canada #4
Magnum gives Shadowfyr a Potion of Cure Confusion.

Where did timers come into play? :)
Australia Forum Administrator #5
I was wondering that too, but thought it best to say nothing, as perhaps I was 'skimming' again. ;)
USA #6
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
Australia Forum Administrator #7
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
#8
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.