Strange If statement behaviour

Blitz3D Forums/Blitz3D Programming/Strange If statement behaviour

CakeMonitor(Posted 2005) [#1]
Well, this takes me back the best part of 20 years... I'm having trouble with an If statement!

I have a 3D world full of cubes and want to generate a tool-tip when the mouse pointer is hovering over any one of them.

here's the main loop:

While Not KeyHit(1)
; Handle Input code [removed to keep post short]


oldSelectedCube = selectedCube
selectedCube = CameraPick(camera,400,300)
If selectedCube Then
showToolTip = True
If selcetedCube <> oldSelectedCube Then SetToolTip(selectedCube)
Else
showToolTip = False
End If


; Update & Display [code removed to keep post short]
Wend


It's the line:
If selcetedCube <> oldSelectedCube Then SetToolTip(selectedCube)
that's giving me grief.

When I move the mouse pointer over a cube the tool tip is displayed correctly, but my SetToolTip() function gets called EVERY frame!

Strangly, if I change the "<>" opperator to "=" the SetToolTip() function isn't called every frame, but... it only gets called when the mouse pointer moves from empty space (no cube) to a cube and not when the pointer moves straight from one cube to another!

Anyone got any ideas?


Rhyolite(Posted 2005) [#2]
Their is a spelling mistake in the code posted, but not sure if thats in your 'real' code as well?

'selceted' instead of 'selected'

Rhy :)


CakeMonitor(Posted 2005) [#3]
Thanks,

You know, I read over that code letter-by-letter three or four times thinking that there was a spelling mistake and just didn't spot it *oops*


Lane(Posted 2005) [#4]
which is wht Blitz desperatly needs an Option Explicit requiring variable declaration.


Neochrome(Posted 2005) [#5]
been programming a bit of code for too long? Its a form of "code-Blind"-ness.
go out for a walk or go out in the car for 30 minutes, come back to it and you see it straight away!


Rhyolite(Posted 2005) [#6]
yeah, happens to all of us ;)

Rhy :)


Hujiklo(Posted 2005) [#7]
Boy I can share that - nearly all my mistakes are of the dumbest of the dumb and obvious variety.

Fresh brain always gets it though.


Banshee(Posted 2005) [#8]
Me too, most of my mistakes tend to involve men and there really isn't anything dumber or simpler ;) hehe


sting(Posted 2005) [#9]
Ya know ive had problems that make a function call all the time but what my solution usualy is is whaen you enter a one time finction set a true false global and have it checked just before you enter it. That should be all you need.


LineOf7s(Posted 2005) [#10]
which is wht Blitz desperatly needs an Option Explicit requiring variable declaration


Well, if you don't like BlitzMax (which includes 'Strict' mode that performs this function), then you could always use The Unofficial BlitzBasic PreProcessor by Michael Richtensteinenburgermeister. Amongst many other features, it also includes:

Option Explicit is enabled by including the preprocessor directive "#Option Explicit" at the top of your source code. It will give an error whenever a variable is implicitly defined.

Find it (for free, nix, nada, zero, dot, The Big Donut) here:
http://www.quickiegames.com/tools/preprocessor/

Kudos to Mr Burgermeister. :o)


John Blackledge(Posted 2005) [#11]
Don't want to be boring, but once again I would like to thank the person would said 'Don't use global variables, use Type elements'.

I've gone back and rewritten whole reams of code since I heard this advice, and now, no more misspelling problems.

Once you declare a type variable (e.g. MyProg\runmode) then you can't misspell runmode again - Blitz will tell you if you do.