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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Chyro

Pages: [1]
1
General / Re: Problem with Event Keyboard Input
« on: November 08, 2018, 09:38:44 pm »
Alright, thanks for the advice.
After a second look I realized that it was in the 'window open' loop, but not inside the poll.event loop.
So I moved the event handler function into the event loop (also the global check for 'Escape' to close the window or go back to title menu, depending on state). And now it works fine.

.. at first I just moved all the main functions into the loop, but realized that makes everything pause as long as there's no event (was kinda funny, the animations and progression always paused unless I kept moving the mouse) but then moved the parts not relevant to events back out ^^

Now everything works as intended, thanks!

2
General / Re: Problem with Event Keyboard Input
« on: November 08, 2018, 01:27:51 pm »
Correct me if I'm wrong, but I think it is inside the event loop?
If you check main.cpp, it's actually that loop that is running everything. On the line
  'currentState->handle_events(window, event);' (marked it with red in the spoiler above)
Is where the code with the issue is being called, with currentState being 'Naming', and that's inside the event loop. I'm passing the sf::event into the function so that it can be used and affected by the different game states while still being the same (one and only) event created in the main loop.

I mean.. if it got stale and invalid data, then the arrow-keys also wouldn't be recognized, no? But they are fully and correctly recognized, with the same code. And it does recognize other keys like Enter, Space, and letters - but only if alt is held while pressing them. Also, in another state (the title menu) that also gets the 'event' passed to it and uses it for checking key presses, the arrow keys as well as Enter + Space inputs get correctly recognized. If I used it wrongly, would stale/invalid data really cause this many keys to be recognized correctly? (not trying to pointlessly argue, but trying to understand why it works fine for the arrow keys and in another state, but not for other keys)

.. I did read the tutorial page about Events multiple times, and I admit I still don't 100% understand it. Am generally learning and trying to understand things through appying them, by trial and error and logic. I do read the theory, but often struggle to understand it until I try out the examples in different scenarios, see how it works, when it doesnt, and then figure out why it doesn't.

(as a side note, normally the program runs through the states starting with INTRO -> INTRO2 -> TITLE -> NAMING, but for testing / debugging I made it start with NAMING. Each of the other states is checking the event from main.cpp for a pressed Enter to progress (title menu also using arrows to navigate), and in each of them it works fine)

3
General / Re: Problem with Event Keyboard Input
« on: November 08, 2018, 01:14:32 pm »
Uh.. okay, full code.
Here we go.
The project is using a state machine, so I guess I'll put in the main code and the code of the state where the issue happens. Probably more than is really needed, but its in convenient spoiler tags so you can just look at the stuff that may be relevant.

.. side note, I'm still quite new to programming (like 2 months or so) so please forgive if there's things in it that are inefficient or should be done in a simpler fashion. Don't mind if anything gets pointed out, as its always good to learn how to do things better. .. I'm just happy when it works the way I intend it to ^^

(click to show/hide)
(click to show/hide)
(click to show/hide)
(click to show/hide)
(click to show/hide)
(click to show/hide)


Oh yeah, looking at it again reminded me of something else.
While checking the keypressed with event doesn't recognize the normal 'Enter' as 'Enter' (enum index 58 of sf::keyboard), the keyreleased does correctly recognize it.
So it's exclusively keypressed that (for some reason) needs alt to be held for 'Enter' to be recognized.

4
General / Problem with Event Keyboard Input
« on: November 08, 2018, 12:06:36 pm »
Hey there.
I'm currently working on a little game project to gather more experience with C++ and SFML.

Now I came across a kinda odd problem while making a visual keyboard for entering a character name.
If I'm using sf::event to check for keypresses ->

(click to show/hide)

It works fine for the arrow keys, to move around the marker to select whatever key on the visual keyboard you want to use. But just below that, when I used the same thing to check if the 'Enter' key got pressed, it didn't work.

(click to show/hide)

After much trying around and looking for solutions, I noticed that for some reason, it only recognizes that 'Enter' key input when I'm holding alt while pressing Enter. Further trying out showed that this applies to most other keys, it only recognizes letter presses (like "N" or "L") or Spacebar if I'm holding alt at the same time. Yet the arrow keys work fine without holding Alt, with the exact same code.

Also, my current now working solution to it - simply using "sf::Keyboard::isKeyPressed(sf::Keyboard::Enter)", does work without the odd issue of having to hold 'Alt'.

So.. I do have a solution to my problem, but I still want to understand why it is causing that weird behavior when using event to check for the key inputs. While trying to figure it out, at one point I used the following code to check what the pressed key is recognized as by outputting it to the console:

(click to show/hide)

Oddly, it output the press of 'Enter' as '13'. Pressing alt + 'Enter' returned '58' which should be the correct value for the key.

Does anyone have an idea what could be causing this?
I figured I'll only put the relevant code here, but if you need I can post all of it.

Though I think I pretty much narrowed the issue down to that one question -
What could cause sf::event require 'alt' being held to recognize 'Enter' correctly, while arrow keys are recognized normally and sf::keyboard also recognizes 'Enter' normally?

(and no, there's nothing in my code doing anything with the 'alt' key or checking for it)

Pages: [1]
anything