Keypress nightmare

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.
Post Reply
Kyx

Keypress nightmare

Post by Kyx »

I've been trying for days to get this simple code right "#$#%&#$%/&:

Here are declarations:

Code: Select all

bool varMove=true;
int varRotate=0;
Here is on KeyInput event in wich I am trying to change varMove from true to false (but it's not working):

Code: Select all

bool OnEvent(SEvent event){ 
  if (event.EventType == EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown){ 
    switch(event.KeyInput.Key){ 
    case KEY_ESCAPE:
		{ 
  varMove = false; 
  return true; 
		}break; 
    } 
  } 
  return false; 
}
and here is setting camera and trying to increase variable varRotate based on state of varMove (wich is working except for commented line) :

Code: Select all

scene::ICameraSceneNode *camera = smgr->addCameraSceneNode(0, core::vector3df(0,0,0), core::vector3df(0,0,0));
driver->beginScene(true, true, video::SColor(0,200,200,200));
smgr->drawAll();
if (varMove==false){ //varMove isn't changing on escape press. Why? 
varRotate+=1;
}
camera->setPosition(core::vector3df(varRotate,50,50)); 
driver->endScene();
Please help me because I am on the verge of nervous breakdown.
Shai-Tan
Posts: 15
Joined: Fri Sep 10, 2004 8:37 pm

Post by Shai-Tan »

I don't think your Case is executing properly.
Course you have Return True inside a case. It never gets to Break;
Try to moving Return true outside of the Case. It should work than something like

Code: Select all

bool OnEvent(SEvent event){ 
  if (event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown){ 
    switch(event.KeyInput.Key){ 
    case KEY_ESCAPE: 
      { 
  varMove = false; 
  
       }break; 
    } 
  } 
  If(varMove == false)
  return true;
else
  return false; 
} 
Guest

Post by Guest »

Whether or not you return true or false has no influence on the value of that variable.
Instructions are carried out in order, and that means that if the code is reached, it is executed. Regardles of what you "return".

I would suggest two things:
1. Purely for testing purposes, move your varMove= false to the top of the event receiver code, so you can check whether or not the event receiver gets called at all.
2. Check how many varMove variables you have. Are you sure your event receiver modifies the same one?
- E.g. does the event receiver have a member variable by that name
- are there both a global and a local variable?
- are you using different source files and declaring the same variable without the external keyword in all but one file?
Post Reply