Event Reciever not responding to GUI Press Event

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
remark
Posts: 14
Joined: Wed May 28, 2014 5:02 am

Event Reciever not responding to GUI Press Event

Post by remark »

So the basic problem is that in my event receiver, I have 2 if statements for events, key presses and gui button presses, however, only only the key press events are working, I have tried searching it up online, but the only solution I could find was to change "return true" to "return false", which didn't work, I also found something about doing 2 event receivers, but I did not understand it at all, and it should be unnecessary. Any help would be very much appreciated!

Code: Select all

 
class MyEventReceiver : public IEventReceiver
{
 
public:
    MyEventReceiver(SAppContext & context) : Context(context)
    {
        for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
            KeyIsDown[i] = false;
    }
 
    virtual bool OnEvent(const SEvent& event)
    {
if (event.EventType == EET_KEY_INPUT_EVENT)
        {
          ...
        }
if (event.EventType == EET_GUI_EVENT)
        {
           ...
        }
private:
    SAppContext & Context;
    bool KeyIsDown[KEY_KEY_CODES_COUNT];
}
 
Neirdan
Posts: 39
Joined: Tue Aug 14, 2012 10:29 pm

Re: Event Reciever not responding to GUI Press Event

Post by Neirdan »

Did you try switching the if statements? What was the result?
remark
Posts: 14
Joined: Wed May 28, 2014 5:02 am

Re: Event Reciever not responding to GUI Press Event

Post by remark »

nothing changed, keyboard keys still worked and gui buttons failed
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Event Reciever not responding to GUI Press Event

Post by CuteAlien »

Please post the complete event-receiver - the code above doesn't show the bug.
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
remark
Posts: 14
Joined: Wed May 28, 2014 5:02 am

Re: Event Reciever not responding to GUI Press Event

Post by remark »

Code: Select all

 
class MyEventReceiver : public IEventReceiver
{
    int x,y,z;
    int new_x,new_y,new_z;
    int counter;
 
public:
    MyEventReceiver(SAppContext & context) : Context(context)
    {
        for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
            KeyIsDown[i] = false;
    }
 
 
    virtual bool OnEvent(const SEvent& event)
    {
        if (event.EventType == EET_KEY_INPUT_EVENT)
        {
            if (animation_check == -1)
            {
                anim = Context.smgr->createFlyStraightAnimator(core::vector3df(Context.camera->getPosition()),core::vector3df(Context.camera->getPosition()), 1, false);
                Context.camera->addAnimator(anim);
                animation_check = 0;
            }
            switch(event.KeyInput.Key)
            {
                 case (irr::KEY_KEY_S):
                       ...(camera adjustment stuff)
                       return false;
                 other cases for keys adjusting camera stuff
               
                 default:
                          return false;
            if (event.EventType == EET_GUI_EVENT)
        {
            if (animation_check == -1)
            {
                anim = Context.smgr->createFlyStraightAnimator(core::vector3df(Context.camera->getPosition()),core::vector3df(Context.camera->getPosition()), 1, false);
                Context.camera->addAnimator(anim);
                animation_check = 0;
            }
            for (int temp_x = 0;temp_x < length;temp_x++)
                {
                    for (int temp_y = 0;temp_y < width; temp_y++)
                        {
                            if(maze_map[temp_x][temp_y] == 'P')
                            {
                                cout<<"test";
                                x = temp_x;
                                y = temp_y;
                                break;
                            }
                        }
                }
            s32 id = event.GUIEvent.Caller->getID();
            IGUIEnvironment* env = Context.device->getGUIEnvironment();
 
            switch(event.GUIEvent.EventType)
            {
                case EGET_BUTTON_CLICKED:
                    cout<<id;
                switch(id)
                {
                    case GUI_ID_Left_Arrow_X:
                        {
                               ...same exact camera adjustments as key presses
                               return false;
                         }
                      default:
                                 return false;
                 }
            return false;
        }
    }
private:
    SAppContext & Context;
    bool KeyIsDown[KEY_KEY_CODES_COUNT];
};
 
Im going to guess the brackets and such dont match up, but it all works, and the actually gui buttons worked until I added the keyboard events
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Event Reciever not responding to GUI Press Event

Post by CuteAlien »

Your check for if (event.EventType == EET_GUI_EVENT) is inside the default: section of a switch for keys. And that switch is even inside a previous check if the eventType is a EET_KEY_INPUT_EVENT. So you need at least 2 closing brackes after your "default: return false". Currently all your gui code is never even called (as you return from the function immediately before that code... with the right settings your compiler should even warn you about unreachable code).
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
remark
Posts: 14
Joined: Wed May 28, 2014 5:02 am

Re: Event Reciever not responding to GUI Press Event

Post by remark »

The code I put up before was the shortened version, so you didnt have to scroll through the repetitive steps taken in each case statement, But like I said before, In the actual program, where I didnt cut and paste specific sections, it works great, or at least it should, if you want, I can post the whole thing, but it is about 1500 lines of code, so I tried to simplify it
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Event Reciever not responding to GUI Press Event

Post by CuteAlien »

When your event-receiver get's to 1500 lines it's probably about time to put some stuff into other functions :-) The thing is - we can't see what's wrong. Checking for keys and gui is something pretty much every app does - there is usually no problem doing that. It has to be something in your code. Maybe start by making one function per event-type (gui, input) - then you can set a breakpoint in the gui and step through to see what's going on when you get a gui-event. Or if you get the button-click event at all.
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
remark
Posts: 14
Joined: Wed May 28, 2014 5:02 am

Re: Event Reciever not responding to GUI Press Event

Post by remark »

Thats the thing, The Gui works on its own, but its only when I added the keys it messed up, removing the keys input restores the gui inputs, and I cant put a breakpoint for when I get a gui event beacuse after some testing I found that the gui event is not being received period, though the gui hover seems to trigger
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Event Reciever not responding to GUI Press Event

Post by CuteAlien »

Using the debugger isn't the only way to debug code. The first step is always to locate the problem - if you have 1500 lines in your eventreceiver then throw out 1490 of them. Keep the code for catching keys and gui events and check again. If it still fails you have a 10 line example to post. If it works now then start adding back your code until you get to the real problem.

I suppose it's obvious that we cannot help you debugging code without even seeing it. Only thing I can tell you is that gui and key events can both be checked in an eventreceiver - everyone is doing that - so the bug is very likely in your code.
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
Post Reply