I was wondering why the encasing brackets "{ }" where needed inside of the cases for this switch event, if I remove them I get these errors from my compiler:
error: Jump to case label
error: Crosses initialization of "irr::core::vector3df v"
Code: Select all
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
if (node != 0 && event.EventType == irr::EET_KEY_INPUT_EVENT &&
!event.KeyInput.PressedDown)
{
switch(event.KeyInput.Key)
{
case KEY_KEY_W:
case KEY_KEY_S:
{
core::vector3df v = node->getPosition();
v.Y += event.KeyInput.Key == KEY_KEY_W ? 2.0f : -2.0f;
node->setPosition(v);
}
return true;
}
}
return false;
}
};