Problem with code

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
Vintige
Posts: 11
Joined: Tue Nov 13, 2007 10:57 am

Problem with code

Post by Vintige »

Im having ptobem with my code, and im getting these error. think its something to do with the class

Code: Select all

1>------ Build started: Project: LoadIrrFile_vc8, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>c:\users\ollystac\desktop\irrlicht\include\masteventreceiver.cpp(36) : error C2011: 'MastEventReceiver' : 'class' type redefinition
1>        c:\users\ollystac\desktop\irrlicht\include\masterevents.h(36) : see declaration of 'MastEventReceiver'
1>c:\users\ollystac\desktop\irrlicht\examples\15.loadirrfile\main.cpp(116) : error C2079: 'receiver' uses undefined class 'MastEventReceiver'
1>c:\users\ollystac\desktop\irrlicht\examples\15.loadirrfile\main.cpp(123) : error C2228: left of '.init' must have class/struct/union
1>        type is 'int'
1>c:\users\ollystac\desktop\irrlicht\examples\15.loadirrfile\main.cpp(125) : error C2228: left of '.endEventProcess' must have class/struct/union
1>        type is 'int'
1>c:\users\ollystac\desktop\irrlicht\examples\15.loadirrfile\main.cpp(128) : error C2664: 'irr::createDevice' : cannot convert parameter 7 from 'int *' to 'irr::IEventReceiver *'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\ollystac\desktop\irrlicht\examples\15.loadirrfile\main.cpp(786) : warning C4244: '=' : conversion from 'irr::f32' to 'int', possible loss of data
1>c:\users\ollystac\desktop\irrlicht\examples\15.loadirrfile\main.cpp(787) : warning C4244: '=' : conversion from 'irr::f32' to 'int', possible loss of data
1>c:\users\ollystac\desktop\irrlicht\examples\15.loadirrfile\main.cpp(788) : warning C4244: '=' : conversion from 'irr::f32' to 'int', possible loss of data
1>c:\users\ollystac\desktop\irrlicht\examples\15.loadirrfile\main.cpp(801) : error C2228: left of '.keyDown' must have class/struct/union
1>        type is 'int'
1>c:\users\ollystac\desktop\irrlicht\examples\15.loadirrfile\main.cpp(801) : error C2228: left of '.keyDown' must have class/struct/union
1>        type is 'int'
1>c:\users\ollystac\desktop\irrlicht\examples\15.loadirrfile\main.cpp(821) : error C2228: left of '.keyDown' must have class/struct/union
1>        type is 'int'
1>c:\users\ollystac\desktop\irrlicht\examples\15.loadirrfile\main.cpp(821) : error C2228: left of '.keyDown' must have class/struct/union
1>        type is 'int'
1>c:\users\ollystac\desktop\irrlicht\examples\15.loadirrfile\main.cpp(841) : error C2228: left of '.keyDown' must have class/struct/union
1>        type is 'int'
1>c:\users\ollystac\desktop\irrlicht\examples\15.loadirrfile\main.cpp(841) : error C2228: left of '.keyDown' must have class/struct/union
1>        type is 'int'
1>c:\users\ollystac\desktop\irrlicht\examples\15.loadirrfile\main.cpp(861) : error C2228: left of '.keyDown' must have class/struct/union
1>        type is 'int'
1>c:\users\ollystac\desktop\irrlicht\examples\15.loadirrfile\main.cpp(861) : error C2228: left of '.keyDown' must have class/struct/union
1>        type is 'int'
1>c:\users\ollystac\desktop\irrlicht\examples\15.loadirrfile\main.cpp(881) : error C2228: left of '.keyDown' must have class/struct/union
1>        type is 'int'
1>c:\users\ollystac\desktop\irrlicht\examples\15.loadirrfile\main.cpp(897) : error C2228: left of '.keyDown' must have class/struct/union
1>        type is 'int'
1>c:\users\ollystac\desktop\irrlicht\examples\15.loadirrfile\main.cpp(906) : error C2228: left of '.keyDown' must have class/struct/union
1>        type is 'int'
1>c:\users\ollystac\desktop\irrlicht\examples\15.loadirrfile\main.cpp(910) : error C2228: left of '.keyDown' must have class/struct/union
1>        type is 'int'
1>c:\users\ollystac\desktop\irrlicht\examples\15.loadirrfile\main.cpp(915) : error C2228: left of '.keyDown' must have class/struct/union
1>        type is 'int'
1>c:\users\ollystac\desktop\irrlicht\examples\15.loadirrfile\main.cpp(950) : warning C4244: '=' : conversion from 'irr::f32' to 'int', possible loss of data
1>c:\users\ollystac\desktop\irrlicht\examples\15.loadirrfile\main.cpp(951) : warning C4244: '=' : conversion from 'irr::f32' to 'int', possible loss of data
1>c:\users\ollystac\desktop\irrlicht\examples\15.loadirrfile\main.cpp(952) : warning C4244: '=' : conversion from 'irr::f32' to 'int', possible loss of data
1>c:\users\ollystac\desktop\irrlicht\examples\15.loadirrfile\main.cpp(2059) : warning C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data
1>c:\users\ollystac\desktop\irrlicht\examples\15.loadirrfile\main.cpp(2085) : error C2228: left of '.startEventProcess' must have class/struct/union
1>        type is 'int'
1>Build log was saved at "file://c:\Users\ollystac\Desktop\irrlicht\examples\15.LoadIrrFile\Debug\BuildLog.htm"
1>LoadIrrFile_vc8 - 19 error(s), 7 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
i cant paste all my code because its 2 big but if any1 wants me to paste an specific piece of it that will b ok.
Thankyou for any help
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

You could always paste it on Rafb and leave whether it is too big or not up to the discretion of the person helping you.

People aren't going to get a lot out of semi-cryptic messages from the console when they don't have the code in front of them. And also, are you building in Debug mode on purpose?
TheQuestion = 2B || !2B
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

well, it seems you're declaring the event receiver twice...
look at the first both messages:

Code: Select all

1>c:\users\ollystac\desktop\irrlicht\include\masteventreceiver.cpp(36) : error C2011: 'MastEventReceiver' : 'class' type redefinition
1>        c:\users\ollystac\desktop\irrlicht\include\masterevents.h(36) : see declaration of 'MastEventReceiver' 
they tell you pretty well what you did wrong and where and what you should do... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Never include cpp files is a good hint.
Vintige
Posts: 11
Joined: Tue Nov 13, 2007 10:57 am

Post by Vintige »

hybrid wrote:Never include cpp files is a good hint.
Ive just followed the instructions from here
Ive fixed the redefinition problem but still getting the others
Last edited by Vintige on Mon Mar 31, 2008 2:10 pm, edited 1 time in total.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

It's MastEventReceiver not MastEventReciever.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Vintige
Posts: 11
Joined: Tue Nov 13, 2007 10:57 am

Post by Vintige »

CuteAlien wrote:It's MastEventReceiver not MastEventReciever.
I know its just i spelt it wrong when i saved the class
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Vintige wrote:
CuteAlien wrote:It's MastEventReceiver not MastEventReciever.
I know its just i spelt it wrong when i saved the class
I'm not talking about the filename, but about the classname. Which you probably copy&pasted, so I guess it's still MastEventReceiver and therefore your variable using an unknown class MastEventReciever.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Vintige
Posts: 11
Joined: Tue Nov 13, 2007 10:57 am

Post by Vintige »

OMG im useless lol :oops:
Thanks for that mate :)
VintigeUK
Posts: 3
Joined: Thu Nov 08, 2007 9:31 pm

Post by VintigeUK »

Im now having another problem now.

Unhandled exception at 0x0040128d in LoadIrrFile.exe: 0xC0000005: Access violation reading location 0x00000003.

it stops at the line

Code: Select all

if (event.EventType == EET_KEY_INPUT_EVENT)
Heres my code for the class

Code: Select all

#include "H:\irrlicht\irrlicht-1.4\include\irrlicht.h" 

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

/// ============================== 
/// MastEventReceiver 
/// ============================== 
class MastEventReceiver : public IEventReceiver 
{ 

   protected: 
   // Enumeration for UP, DOWN, PRESSED and RELEASED key states. Also used for mouse button states. 
   enum keyStatesENUM {UP, DOWN, PRESSED, RELEASED}; 

   // Enumeration for Event Handling State. 
   enum processStateENUM {STARTED, ENDED}; 

   // Mouse button states. 
   keyStatesENUM mouseButtonState[2]; //Left(0), Middle(1) and Right(2) Buttons. 

   // Keyboard key states. 
   keyStatesENUM keyState[KEY_KEY_CODES_COUNT]; 

   // Mouse X/Y coordinates and Wheel data. 
   struct mouseData 
   { 
   int X; 
   int Y; 
   float wheel; //wheel is how far the wheel has moved 
   }; 
   struct mouseData mouse; 

   processStateENUM processState; // STARTED = handling events, ENDED = not handling events 

   virtual bool OnEvent(const SEvent &event) 
   { 
      bool eventprocessed = false; 

      ////////////////////////////// 
      // Keyboard Input Event 
      ////////////////////////////// 
      if (event.EventType == EET_KEY_INPUT_EVENT) 
      { 
         if (processState == STARTED) 
         { 
            // if key is Pressed Down 
            if (event.KeyInput.PressedDown == true) 
            { 
               // If key was not down before 
               if (keyState[event.KeyInput.Key] != DOWN) 
               { 
                  keyState[event.KeyInput.Key] = PRESSED; // Set to Pressed 
               } 
               else 
               { 
                  // if key was down before 
                  keyState[event.KeyInput.Key] = DOWN; // Set to Down 
               } 
            } 
            else 
            { 

                  // if the key is down 
                  if (keyState[event.KeyInput.Key] != UP) 
                  { 
                     keyState[event.KeyInput.Key] = RELEASED; // Set to Released 
                  } 
            } 
         } 


         eventprocessed = true; 
      } 

      ////////////////////////////// 
      // Mouse Input Event 
      ////////////////////////////// 

      if (event.EventType == EET_MOUSE_INPUT_EVENT) 
      { 
         if (processState == STARTED) 
         { 
            //Mouse changed position 
            if (event.MouseInput.Event == EMIE_MOUSE_MOVED) 
            { 
               mouse.Y = event.MouseInput.Y; 
               mouse.X = event.MouseInput.X; 
            } 

            //Wheel moved. 
            if (event.MouseInput.Event == EMIE_MOUSE_WHEEL) 
            { 
               mouse.wheel += event.MouseInput.Wheel; 
            } 

            //Left Mouse Button Pressed 
            if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) 
            { 
               // 
               if (mouseButtonState[0] == UP || mouseButtonState[0] == RELEASED) 
               { 
                  mouseButtonState[0] = PRESSED; 
               } 
               else 
               { 
                  mouseButtonState[0] = DOWN; 
               } 
            } 

            //Left Mouse Button Rleased 
            if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) 
            { 
               // 
               if (mouseButtonState[0] != UP) 
               { 
                  mouseButtonState[0] = RELEASED; 
               } 
            } 

            //Middle Mouse Button Pressed 
            if (event.MouseInput.Event == EMIE_MMOUSE_PRESSED_DOWN) 
            { 
               // 
               if (mouseButtonState[1] == UP || mouseButtonState[1] == RELEASED) 
               { 
                  mouseButtonState[1] = PRESSED; 
               } 
               else 
               { 
                  mouseButtonState[1] = DOWN; 
               } 
            } 

            //Middle Mouse Button Rleased 
            if (event.MouseInput.Event == EMIE_MMOUSE_LEFT_UP) 
            { 
               // 
               if (mouseButtonState[1] != UP) 
               { 
                  mouseButtonState[1] = RELEASED; 
               } 
            } 

            //Right Mouse Button Pressed 
            if (event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN) 
            { 
               // 
               if (mouseButtonState[2] == UP || mouseButtonState[2] == RELEASED) 
               { 
                  mouseButtonState[2] = PRESSED; 
               } 
               else 
               { 
                  mouseButtonState[2] = DOWN; 
               } 
            } 

            //Right Mouse Button Rleased 
            if (event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP) 
            { 
               // 
               if (mouseButtonState[2] != UP) 
               { 
                  mouseButtonState[2] = RELEASED; 
               } 
            } 
         } 


         eventprocessed = true; 
      } 


      return eventprocessed; 
   } 


   ////////////////////// 
   // Public functions 
   ////////////////////// 
   public: 

   float mouseWheel() 
   { 
      return mouse.wheel; 
   } 

   int mouseX() 
   { 
      return mouse.X; 
   } 

   int mouseY() 
   { 
      return mouse.Y; 
   } 

   bool leftMouseReleased() 
   { 
      if (mouseButtonState[0] == RELEASED) 
      { 
         return true; 
      } 
      else 
      { 
         return false; 
      } 
   } 
   bool leftMouseUp() 
   { 
      if (mouseButtonState[0] == RELEASED || mouseButtonState[0] == UP) 
      { 
         return true; 
      } 
      else 
      { 
         return false; 
      } 
   } 

   bool leftMousePressed() 
   { 
      if (mouseButtonState[0] == PRESSED) 
      { 
         return true; 
      } 
      else 
      { 
         return false; 
      } 
   } 

   bool leftMouseDown() 
   { 
      if (mouseButtonState[0] == PRESSED || mouseButtonState[0] == DOWN) 
      { 
         return true; 
      } 
      else 
      { 
         return false; 
      } 
   } 

   bool middleMouseReleased() 
   { 
      if (mouseButtonState[1] == RELEASED) 
      { 
         return true; 
      } 
      else 
      { 
         return false; 
      } 
   } 
   bool middleMouseUp() 
   { 
      if (mouseButtonState[1] == RELEASED || mouseButtonState[1] == UP) 
      { 
         return true; 
      } 
      else 
      { 
         return false; 
      } 
   } 

   bool middleMousePressed() 
   { 
      if (mouseButtonState[1] == PRESSED) 
      { 
         return true; 
      } 
      else 
      { 
         return false; 
      } 
   } 

   bool middleMouseDown() 
   { 
      if (mouseButtonState[1] == PRESSED || mouseButtonState[1] == DOWN) 
      { 
         return true; 
      } 
      else 
      { 
         return false; 
      } 
   } 

   bool rightMouseReleased() 
   { 
      if (mouseButtonState[2] == RELEASED) 
      { 
         return true; 
      } 
      else 
      { 
         return false; 
      } 
   } 
   bool rightMouseUp() 
   { 
      if (mouseButtonState[2] == RELEASED || mouseButtonState[2] == UP) 
      { 
         return true; 
      } 
      else 
      { 
         return false; 
      } 
   } 

   bool rightMousePressed() 
   { 
      if (mouseButtonState[2] == PRESSED) 
      { 
         return true; 
      } 
      else 
      { 
         return false; 
      } 
   } 

   bool rightMouseDown() 
   { 
      if (mouseButtonState[2] == PRESSED || mouseButtonState[2] == DOWN) 
      { 
         return true; 
      } 
      else 
      { 
         return false; 
      } 
   }// 

   bool keyPressed(char keycode) 
   { 
      if (keyState[keycode] == PRESSED) 
      { 
         return true; 
      } 
      else 
      { 
         return false; 
      } 
   } 

   bool keyDown(char keycode) 
   { 
      if (keyState[keycode] == DOWN || keyState[keycode] == PRESSED) 
      { 
         return true; 
      } 
      else 
      { 
         return false; 
      } 
   } 

   bool keyUp(char keycode) 
   { 
      if (keyState[keycode] == UP || keyState[keycode] == RELEASED) 
      { 
         return true; 
      } 
      else 
      { 
         return false; 
      } 
   } 

   bool keyReleased(char keycode) 
   { 
      if (keyState[keycode] == RELEASED) 
      { 
         return true; 
      } 
      else 
      { 
         return false; 
      } 
   } 


   // This is used so that the Key States will not be changed during execution of your Main game loop. 
   // Place this at the very START of your Main Loop 
   void endEventProcess() 
   { 
      processState = ENDED; 
   } 

   // This is used so that the Key States will not be changed during execution of your Main game loop. 
   // Place this function at the END of your Main Loop. 
   void startEventProcess() 
   { 

      processState = STARTED; 
      //Keyboard Key States 
      for (int i = 0; i < KEY_KEY_CODES_COUNT; i++) 
      { 
         if (keyState[i] == RELEASED) 
         { 
            keyState[i] = UP; 
         } 

         if (keyState[i] == PRESSED) 
         { 
            keyState[i] = DOWN; 
         } 
      } 
      //Mouse Button States 
      for (int i = 0; i <= 2; i++) 
      { 
         if (mouseButtonState[i] == RELEASED) 
         { 
            mouseButtonState[i] = UP; 
         } 

         if (mouseButtonState[i] == PRESSED) 
         { 
            mouseButtonState[i] = DOWN; 
         } 
      } 
      //Mouse Wheel state 
      mouse.wheel = 0.0f; 

   } 

   void init() 
   { 
      //KeyBoard States. 
      for (int i = 0; i <= KEY_KEY_CODES_COUNT; i++) 
      { 
         keyState[i] = UP; 
      } 
      //Mouse states 
      for (int i = 0; i <= 2; i++) 
      { 
         mouseButtonState[i] = UP; 
      } 
      //Mouse X/Y coordenates. 
      mouse.X = 0; 
      mouse.Y = 0; 
      mouse.wheel = 0.0f; 
   } 


}; 
/// ========================================== 
/// END OF MastEventReceiver 
/// ==========================================
Thankyou for any help
Vintige
Posts: 11
Joined: Tue Nov 13, 2007 10:57 am

Post by Vintige »

bump
Post Reply