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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  VBscript
. . -> [Subject]  Problems with numbers

Problems with numbers

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Edgeofforever   (25 posts)  [Biography] bio
Date Fri 26 Nov 2004 05:02 PM (UTC)
Message
I'm having a problem with a script I've been writing.
I use the following trigger to get a number in representing the number of a certain potion in a container.

^\s*(a|an)\s*(sanctuary|bless|fly|armor|protection|true|create|alertness|dispel|grounding|heal|cure|empty)\s*(blindness|poison|magic|spring|sight|)\s*(potion|flask)\s*\(\s*(\d+)\s*\)\s*$

It sends the number to a script and puts it into a variable. I created another variable:

maxLong = 1500

Then later in the scrip I compare the two like this:

if sanctuary < max long then

Where sanctuary is the number brought in from the trigger. Even when sanctuary is clearly less then 1500, it doesn't go through the if code. Can anyone help?
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Fri 26 Nov 2004 08:20 PM (UTC)
Message
This is the classic problem of confusing numbers with strings. We can reproduce it in the Immediate window like this:


SetVariable "sanctuary", 22
SetVariable "maxlong", 1500

sanctuary = GetVariable ("sanctuary")
maxLong = GetVariable ("maxlong")

if sanctuary  < maxLong then
  Note "Pass"
else
  Note "Fail"
end if


Run this, and it prints "Fail".

This is because it compares "22" to "1500" and thinks 22 is higher, which it is as a string. This works, converting both numbers to integer:


sanctuary = CInt (GetVariable ("sanctuary"))
maxLong = CInt (GetVariable ("maxlong"))



Other languages would have similar syntax. For example in Lua you need to use "tonumber" to do the conversion.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Edgeofforever   (25 posts)  [Biography] bio
Date Reply #2 on Sun 28 Nov 2004 06:53 AM (UTC)
Message
Perfect, thanks.
[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.


9,605 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]