Problem with ifs

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
kburkhart84
Posts: 277
Joined: Thu Dec 15, 2005 6:11 pm

Post by kburkhart84 »

vitek wrote:Violet,

You are totally off base here. CuteAlien is right, there is no way in hell that the compiler is generating bad code because you're using Irrlicht. The problem is that you are using Irrlicht incorrectly, and you are jumping to conclusions. Honestly.

From looking at your code I would guess that the problem is in the event receiver [as pointed to by CuteAlien]. You are misinterpreting the use of the KeyInput.Key member. That is the key code for the key that was pressed, but you are using it like it is an indicator to see if the key is pressed down or not.

Travis
This is exactly right. I'll detail the code I see in the event handler.

Code: Select all

//at this point, you know a key is pressed, but not which one
switch(event.KeyInput.Key) //here you give what to do according to each different key
         { 
            // Camera. 
            case KEY_UP://if the key is the up arrow key 
            inputUp = event.KeyInput.Key; //inputUp now equals KEY_UP
            break; remember, you just used event.KeyInput.Key to say whether it is KEY_UP, KEY_DOWN, or KEY_ESCAPE, and now you just set the variable "inputUp" to equal whatever is in event.KeyInput.Key, which in this case is "KEY_UP"
            case KEY_DOWN: 
            inputDown = event.KeyInput.Key; 
            break; //You did the same here except for it is KEY_DOWN now.
            // Inputs. 
            case KEY_ESCAPE: 
            if (!event.KeyInput.PressedDown) 
            { 
               inputEsc = event.KeyInput.Key; //once again, see what you did.
            } 
            break; 

After looking at your code, you simply check what key was pressed, and then set a variable to "the key that was pressed", when instead you probably need to set it to "true" or "false" since the variables you are using already represent the key that was pressed. For example, inputUp should be a bool, that you later on check if it is true, and if it is, move up, or throttle, or whatever your hero is doing in your game. inputUp, inputDown, and inputEsc are all "bool" type variables according to your code, but you are telling them they need to equal whatever key is down.

Hopefully, that should give you an idea what you are doing wrong. Also, don't take this wrong, but until you are more familiar with the engine and programming in C++, please don't assume a bug on the engine. Ask first, and preferably politely. I've never seen you post before, which is why I chose to help you even after seeing your rude posts from above. So please, be respectful, as it is much easier to give help to a respectable person who politely asks for the help instead of expecting us to do the homework. I personally appreciate the community here and I myself am no expert, but check my post history. Every request for help I've had resulted in good answers, mainly because I asked nicely.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

I'm having a problem with some native BREW UI code, but since I had this thread up on screen when the bug occurred, I think the code posted here must be causing it. Voilet, I need you to debug my BREW native code for me, since you broke it.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
kburkhart84
Posts: 277
Joined: Thu Dec 15, 2005 6:11 pm

Post by kburkhart84 »

rogerborg wrote:I'm having a problem with some native BREW UI code, but since I had this thread up on screen when the bug occurred, I think the code posted here must be causing it. Voilet, I need you to debug my BREW native code for me, since you broke it.
That's mean. It sounds about right though. I'm glad I didn't have any IDEs open when I looked at the post myself because I already have too many of my own bugs to work out without having some added on by random code from a phpBB2 forum :D
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

kburkhart84 wrote:That's mean.
It was meant to be. Developers who assume and insist that the problem must be with everybody else are either genii if they're consistently right, or completely toxic if they're not, which they usually aren't.

Mea culpa, by the way: I reported a noob non-bug yesterday due to not RTFMing, but the difference is that I cheerfully apologised for wasting hybrid's time. We all make mistakes; what matters is accepting responsibility for doing so, rather than just shrieking louder when your snafu is exposed.

I will of course apologise for being mean if Violet apologises for being a nobjockey. ;)
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
kburkhart84
Posts: 277
Joined: Thu Dec 15, 2005 6:11 pm

Post by kburkhart84 »

rogerborg wrote:
kburkhart84 wrote:That's mean.
...

I will of course apologise for being mean if Violet apologises for being a nobjockey. ;)
Don't worry. I don't expect you to apoligize for it, especially since you are right. We all make mistakes, including me, but what's important is that we admit and correct them instead of pretending that they don't exist.
Post Reply