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
➜ VBscript
➜ Problems with numbers
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Edgeofforever
(25 posts) 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? | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) 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 | | 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.
13,054 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top