[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  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] Refresh page


Posted by Guy Styles   (4 posts)  [Biography] 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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] 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
[Go to top] top

Posted by Guy Styles   (4 posts)  [Biography] bio
Date Reply #2 on Wed 28 Aug 2002 09:22 PM (UTC)
Message
Ahh. heck yeah!
Thanks Nick Gammon!
[Go to top] top

Posted by Shadowfyr   USA  (1,786 posts)  [Biography] 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. ;)
[Go to top] top

Posted by Magnum   Canada  (580 posts)  [Biography] 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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] 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
[Go to top] top

Posted by Shadowfyr   USA  (1,786 posts)  [Biography] 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
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] 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
[Go to top] top

Posted by Guy Styles   (4 posts)  [Biography] 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.
[Go to top] 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] Refresh page

Go to topic:           Search the forum


[Go to top] 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.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]