Tutorial19 Mouse input copy/pasted does not work. WHY ç_ç

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
Gnasty Gnork
Posts: 18
Joined: Fri Jun 20, 2014 12:12 pm

Tutorial19 Mouse input copy/pasted does not work. WHY ç_ç

Post by Gnasty Gnork »

The issue is for sure how i split the declaration/ definition but i cant figure out what is wrong.

Here are the source files:

EventReceiver.h

Code: Select all

using namespace irr;
 
 
 
class MyEventReceiver : public IEventReceiver
{
 
private:
    bool KeyIsDown[KEY_KEY_CODES_COUNT];
    bool KeyIsUp[KEY_KEY_CODES_COUNT];
    struct SMouseState;
 
public:
    MyEventReceiver();  
    virtual bool OnEvent(const SEvent& event);
    virtual bool IsKeyDown(EKEY_CODE keyCode) const;
    virtual bool IsKeyUp(EKEY_CODE keyCode) const;
    const SMouseState& GetMouseState() const;
};
EventReceiver.cpp

Code: Select all

#include <irrlicht.h>
#include <string>
#include "EventReceiver.h"
#include "Game.h"
 
//using namespace std;
using namespace irr;
 
 
struct SMouseState{
    core::vector2di Position;
    bool LeftButtonDown;
    SMouseState() : LeftButtonDown(false) { }
} MouseState;
 
    // This is the one method that we have to implement
      bool MyEventReceiver::OnEvent(const SEvent& event){
          // Remember whether each key is down or up
          if (event.EventType == irr::EET_KEY_INPUT_EVENT)
          {
              KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
          }
 
          // Remember the mouse state
          if (event.EventType == irr::EET_MOUSE_INPUT_EVENT)
          {
              switch (event.MouseInput.Event)
              {
              case EMIE_LMOUSE_PRESSED_DOWN:
                  MouseState.LeftButtonDown = true;
                  break;
 
              case EMIE_LMOUSE_LEFT_UP:
                  MouseState.LeftButtonDown = false;
                  break;
 
              case EMIE_MOUSE_MOVED:
                  MouseState.Position.X = event.MouseInput.X;
                  MouseState.Position.Y = event.MouseInput.Y;
                  break;
 
              default:
                  // We won't use the wheel
                  break;
                  
              }
          }
          return false;
      }
    // This is used to check whether a key is being held down
     bool MyEventReceiver::IsKeyDown(EKEY_CODE keyCode) const
    {
        return KeyIsDown[keyCode];
    }
 
     bool MyEventReceiver::IsKeyUp(EKEY_CODE keyCode) const
     {
         return KeyIsUp[keyCode];
     }
    MyEventReceiver::MyEventReceiver()
    {
        for (u32 i = 0; i < KEY_KEY_CODES_COUNT; i++)
        {
            KeyIsDown[i] = false;
            KeyIsUp[i] = true;
        }
    }
 
 
const SMouseState& GetMouseState() 
    {
    return  MouseState;
    }
    
 
 
    // We use this array to store the current state of each key
    
    //bool MyEventReceiver::KeyIsDown[KEY_KEY_CODES_COUNT];
 
But when in main/player.cpp or wherever i try to call the GetMouseState() function using:

Code: Select all

 game.receiver.GetMouseState() 
I cant access the members of MouseState using for example

Code: Select all

 game.receiver.GetMouseState().LeftButtonDown 
Even the intellisense stops at that point...

Is it because main.cpp does not know what SMouseState is? How should i make it a known type elsewhere?

Keyboard works as it should so it has to be something related to GetMouseState()
Thank you guys for the help. :)



EDIT: Oh and if i declare and define the struct SMouseState inside the EventReceiver.H file it works but i get this error:

Code: Select all

error LNK2001: external symbol "public: struct SMouseState const & __thiscall MyEventReceiver::GetMouseState(void)const " (?GetMouseState@MyEventReceiver@@QBEABUSMouseState@@XZ) unresolved    

EDIT2: I guess i got it, brb.


EDIT3: Yeah i m a total noob, ima bookmark this topic for future reference.

Basically i was declaring GetMouseState() outside the class scope.

MyEventReceiver::GetMouseState() fixed it ofc, thats what i get with copy/paste.
Post Reply