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
➜ evaluating expressions
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Tsunami
USA (204 posts) Bio
|
Date
| Thu 28 Oct 2004 05:22 PM (UTC) |
Message
| I have bee trying to get the following expression to evaluate properly, but it seems not to like me.
if (h <= m*f) then
World.note "It worked!"
end if
while testing I made sure h was indeed less than m*f, yet it never evaluated to true. Finally I found that when true, the expression evaluated to 0, and when false, -1.
Therefore I had to change the expression to:
if ((h <= m*f) + 1) then
World.note "It worked!"
end if
It works now, but I was wondering what was going on with that? | Top |
|
Posted by
| Flannel
USA (1,230 posts) Bio
|
Date
| Reply #1 on Thu 28 Oct 2004 06:15 PM (UTC) Amended on Thu 28 Oct 2004 06:19 PM (UTC) by Flannel
|
Message
| True is -1
False is 0
Thats how VBScript is set up.
So, you must have had something wrong initially, since when true it should have evaluated to -1, and false to 0.
Try adding parenthesis around m*f, or make sure theyre all numbers (Cint, or whatever), since sometimes the variants cause problems.
Although it will evaluate to true if its any non zero. But True has a value of -1, and False 0 (as is VbTrue and VbFalse). |
~Flannel
Messiah of Rose
Eternity's Trials.
Clones are people two. | Top |
|
Posted by
| Tsunami
USA (204 posts) Bio
|
Date
| Reply #2 on Thu 28 Oct 2004 08:02 PM (UTC) |
Message
| I didn't know that true was -1, but the expression should have worked in any case. I tried it with parens around m*f and without; the result was the same. *shrug* | Top |
|
Posted by
| Flannel
USA (1,230 posts) Bio
|
Date
| Reply #3 on Thu 28 Oct 2004 09:01 PM (UTC) |
Message
| Did you cast them to numeric values? It could be trying to do a text comparison.
Since obviously the expression is wrong in one way or another. |
~Flannel
Messiah of Rose
Eternity's Trials.
Clones are people two. | Top |
|
Posted by
| Meerclar
USA (733 posts) Bio
|
Date
| Reply #4 on Fri 29 Oct 2004 03:05 AM (UTC) |
Message
| Post the entire script and we can probly be of more help on this, just seeing the calculation doesn't really give us much to work with. |
Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org | Top |
|
Posted by
| Tsunami
USA (204 posts) Bio
|
Date
| Reply #5 on Fri 29 Oct 2004 03:54 PM (UTC) |
Message
| This is the corrected version, the uncorrected version simply didn't have the + 1 inside the ifs.
'h = 100
'm = 100
'mH = World.GetVariable("mH") (= 2900)
'mM = World.getVariable("mM") (= 1900)
sub DoPrompt (name, output, wildcs)
h = wildcs(1)
m = wildcs(2)
if elixirBalance then
if ((h < mH*hF) + 1) then
healElixir "health"
elseif (m <= m*mF) then
healElixir "mana"
end if
end if
if mossBalance then
if ((h <= mH*mF) + 1) then
healMoss
end if
end if
end sub | Top |
|
Posted by
| Nick Gammon
Australia (23,140 posts) Bio
Forum Administrator |
Date
| Reply #6 on Sat 30 Oct 2004 07:29 AM (UTC) |
Message
|
Quote:
h = wildcs(1)
m = wildcs(2)
All this sort of stuff is treating the numbers as strings. Thus the comparison will probably not work.
You have also commented out some of the other assignments:
Quote:
'mH = World.GetVariable("mH") (= 2900)
'mM = World.getVariable("mM") (= 1900)
I would convert them to integers, eg.
mH = CInt (World.GetVariable("mH"))
mM = CInt (World.getVariable("mM"))
...
h = CInt (wildcs(1))
m = CInt (wildcs(2))
|
- 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.
22,100 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top