Strange If statement behaviour
Blitz3D Forums/Blitz3D Programming/Strange If statement behaviour
| ||
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? |
| ||
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 :) |
| ||
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* |
| ||
which is wht Blitz desperatly needs an Option Explicit requiring variable declaration. |
| ||
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! |
| ||
yeah, happens to all of us ;) Rhy :) |
| ||
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. |
| ||
Me too, most of my mistakes tend to involve men and there really isn't anything dumber or simpler ;) hehe |
| ||
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. |
| ||
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) |
| ||
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. |