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

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  VBscript
. . -> [Subject]  evaluating expressions
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

evaluating expressions

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


Posted by Tsunami   USA  (204 posts)  [Biography] 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?
[Go to top] top

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

Posted by Tsunami   USA  (204 posts)  [Biography] 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*
[Go to top] top

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

Posted by Meerclar   USA  (733 posts)  [Biography] 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
[Go to top] top

Posted by Tsunami   USA  (204 posts)  [Biography] 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
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] 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
[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.


6,926 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 FutureQuest]