Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Need Help limiting Key/Mouse Presses!  (Read 2312 times)

0 Members and 1 Guest are viewing this topic.

cooldog99

  • Jr. Member
  • **
  • Posts: 95
    • View Profile
    • Perilous Game Studios
Need Help limiting Key/Mouse Presses!
« on: March 07, 2011, 06:23:14 am »
Ok. So...
I'm using SFML 1.6, and need help with 1 small thing.

I need to limit the user (on certain things) on key presses. basically NOT allowing them to hold a key down, a 1 time key press if you will..
Also need same with mouse.

I understand this can be achieved with using Events, however my code is NOT directly inside main function, and I cannot for some reason transfer Event through a pointer into Game code, why?

I'm basically using this method


transferring events into functions through a pointer like such.

Game::Update(sf::Event * Event)

Any ideas?

Sorry if I'm not clear enough, ask and i'll clear anything up.
Please help!

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Need Help limiting Key/Mouse Presses!
« Reply #1 on: March 07, 2011, 10:22:29 am »
Erhm you should be able to. You probably doing something wrong somewhere else. Do you save away the pointer? What error do you get?

Anyway to limit the user. All you have to do is ignore the event when you don't want it.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

cooldog99

  • Jr. Member
  • **
  • Posts: 95
    • View Profile
    • Perilous Game Studios
Need Help limiting Key/Mouse Presses!
« Reply #2 on: March 07, 2011, 06:59:58 pm »
Quote from: "Groogy"
Erhm you should be able to. You probably doing something wrong somewhere else. Do you save away the pointer? What error do you get?

Anyway to limit the user. All you have to do is ignore the event when you don't want it.


I know, that's what I don't get...

here, lemme show some code snippets.
FYI the code has been reduced, so you don't see our massive bulk code :p

main function
Code: [Select]

                    GameRun(&App, &Event);
                    GameDraw(&App);


Code: [Select]

void GameRun(sf::RenderWindow *app, sf::Event *event)
{
    mainGame.SendVariables(event);
    mainGame.Update();

}


Code: [Select]

void Game::SendVariables(sf::RenderWindow * app, sf::Event * event)
{
    Window = app;
    KeyEvent = event;
}


And then me trying to use it...

Code: [Select]

                    if (KeyEvent->Type == sf::Event::KeyPressed && KeyEvent->Key.Code == sf::Key::N)
                        std::cout << "N" << std::endl;


No errors, it just doesn't "catch" the event, as if it doesn't happen...

cooldog99

  • Jr. Member
  • **
  • Posts: 95
    • View Profile
    • Perilous Game Studios
Need Help limiting Key/Mouse Presses!
« Reply #3 on: March 10, 2011, 07:51:29 am »
Ok so I'm using
Code: [Select]
extern sf::Event WindowEvent; now, and it gets the variable from main.cpp (The main function holder) and I can access it fine inside Game.cpp (main game engine class), however, two things.

I can't use sf::Key as Key.Code identifier, only #'s, and same for Event.Type.

Also KeyRepeat is stuck ON, even though it is set to FALSE. Why?

Please, anyone? I really need help :(

thePyro_13

  • Full Member
  • ***
  • Posts: 156
    • View Profile
Need Help limiting Key/Mouse Presses!
« Reply #4 on: March 10, 2011, 01:06:37 pm »
I recommend getting friendly with your debugger and walking through your event path.

Set a breakpoint a follow the event all the way through your program to find where it gets lost.

It sounds like its working when you use a global so you must be passing it wrong or overwriting it at some point.

cooldog99

  • Jr. Member
  • **
  • Posts: 95
    • View Profile
    • Perilous Game Studios
Need Help limiting Key/Mouse Presses!
« Reply #5 on: March 10, 2011, 07:16:43 pm »
Quote from: "thePyro_13"
I recommend getting friendly with your debugger and walking through your event path.

Set a breakpoint a follow the event all the way through your program to find where it gets lost.

It sounds like its working when you use a global so you must be passing it wrong or overwriting it at some point.



I would use the debugger, but I'm using codeblocks, and everytime I try it hangs for a sec and says "GBD.exe" (or w/e it's called) Is not responding...

 

anything