noobish question

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.
thomas55

noobish question

Post by thomas55 »

ive read though the keybord input page at irrforge but my input code dont work heres my code:

Code: Select all

class MyEventReceiver : public IEventReceiver 
{ 
public: 
virtual bool OnEvent(SEvent event) 
 { 
if (event.EventType == irr::EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown) 

switch(event.KeyInput.Key) 
{ 
case KEY_ESCAPE: 
  { 
irrDevice->closeDevice(); 
break; 
  } 
} 
return false; 
 } 

};
and heres the errors i get
2 C:\Irrlicht\Game\keyinput.h expected class-name before '{' token
4 C:\Irrlicht\Game\keyinput.h `OnEvent' declared as a `virtual' field
4 C:\Irrlicht\Game\keyinput.h expected `;' before '(' token
19 C:\Irrlicht\Game\keyinput.h expected `;' before '}' token

im using dev c++ can someone please help me :?
Guest

Post by Guest »

could you post the whole file?
Guest

Post by Guest »

That code is correct. I think you forgot to include irrlicht.h
Guest

Post by Guest »

we dont know if he does not post the whole file, thats why i asked for it.
thomas55

Post by thomas55 »

i fogot irrlicht.h
thomas55

Post by thomas55 »

#include <irrlicht.h>

class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
if (event.EventType == irr::EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown)

switch(event.KeyInput.Key)
{
case KEY_ESCAPE:
{
irrDevice->closeDevice();
break;
}
}
return false;
}

};

i still ge tthe same errors :?
thomas55

Post by thomas55 »

also for the moment that is the whole file
Guest

Post by Guest »

you forgot to use namespaces:

using namespace irr;
using namespace core;
using namespace video;
using namespace scene;
using namespace gui;
using namespace io;


that are all namespaces.
thomas55

...

Post by thomas55 »

still the same errors when i added all of the namespaces
Guest

Post by Guest »

this is what i did:

1. created a new devc++ console project
2. pasted your code
3. got the same errors

then after i used the namespaces all errors where gone.
thomas55

Post by thomas55 »

1 more error

23 C:\Irrlicht\Game\Keyinput.h `irrDevice' undeclared (first use this function)

heres the code:

Code: Select all


#include <irrlicht.h>

using namespace irr; 
using namespace core; 
using namespace video; 
using namespace scene; 
using namespace gui; 
using namespace io; 

#pragma comment(lib, "Engine.lib")

class MyEventReceiver : public IEventReceiver 
{ 
public: 
virtual bool OnEvent(SEvent event) 
 { 
if (event.EventType == irr::EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown) 

switch(event.KeyInput.Key) 
{ 
case KEY_ESCAPE: 
  { 
 irrDevice->closeDevice(); 
 break; 
  } 
} 
return false; 
 } 

};
thomas55

Post by thomas55 »

it compiles when i take this out

Code: Select all

irrDevice->closeDevice(); 
break;
thomas55

Post by thomas55 »

it compiles but the esc key doesent quit the game
thomas55

Post by thomas55 »

i got it working with the

irrDevice->closeDevice();
break;

sorry about double post
Guest

Post by Guest »

with:

Code: Select all

#include <irrlicht.h>

using namespace irr; 
using namespace core; 
using namespace video; 
using namespace scene; 
using namespace gui; 
using namespace io; 

#pragma comment(lib, "Engine.lib")

class MyEventReceiver : public IEventReceiver 
{ 
public: 
virtual bool OnEvent(SEvent event) 
 { 
if (event.EventType == irr::EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown) 

switch(event.KeyInput.Key) 
{ 
case KEY_ESCAPE: 
  { 
   irrDevice->closeDevice(); 
   break; 
  } 
} 
return false; 
 } 

};

im getting the errors i got at the start again
Post Reply