Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding state caches Key Input #2205

Closed
vildapavlicek opened this issue May 17, 2021 · 3 comments
Closed

Adding state caches Key Input #2205

vildapavlicek opened this issue May 17, 2021 · 3 comments
Labels
A-ECS Entities, components, systems, and events A-Input Player input via keyboard, mouse, gamepad, and more C-Bug An unexpected or incorrect behavior

Comments

@vildapavlicek
Copy link

vildapavlicek commented May 17, 2021

Bevy version

0.5

Operating system & version

Windows 10

What you did

Not sure if this is actually bug or design / usage mistake on my part. If it is not bug, please explain why it is happening.

I have two game states: PlayerTurn & EnemyTurn.
During GameState::PlayerTurn I run system for key input (writes event) and move player sprite according to that input (reads event). If there is any input (directional arrows), player action (movement) is done and I set GameState::EnemyTurn.
During GameState::EnemyTurn I run one system, that only moves enemy sprite left or right and then sets GameState::PlayerTurn. But next player turn there seem to be cached key input because even if I don't press any keys it reports key being pressed and window freezes.

What you expected to happen

After setting GameState::EnemyTurn I expect player systems to run as if no player key was pressed unless it is actually pressed.

What actually happened

After key is once pressed it seems it get stored / cached somewhere and after that system always behaves as if key was pressed although no key was pressed

Additional information

Can be tested with https://github.com/vildapavlicek/wanderer/tree/state-bug
INFO: the game state that makes problems is called TempGameState as there is another one that I used before which is simple resource.

May 17 22:05:25.336  INFO wanderer::systems::player: gs=State { transition: None, stack: [PlayerTurn], scheduled: None, end_next_loop: false }
May 17 22:05:25.336  INFO wanderer::systems::player: action=NoAction <--- No key yet pressed
May 17 22:05:25.336  INFO wanderer::systems::player: msg="player move or attack"
May 17 22:05:25.352  INFO wanderer::systems::player: gs=State { transition: None, stack: [PlayerTurn], scheduled: None, end_next_loop: false }
May 17 22:05:25.352  INFO wanderer::systems::player: msg="Up key pressed" <--- Actually presed key
May 17 22:05:25.352  INFO wanderer::systems::player: action=Movement(1, 2)
May 17 22:05:25.353  INFO wanderer::systems::player: msg="player move or attack"
May 17 22:05:25.353  INFO wanderer::systems::player: msg="moving player"
May 17 22:05:25.353  INFO wanderer::systems::player: msg="setting state to EnemyTurn" change_state=true
May 17 22:05:25.353  INFO wanderer::systems::player: msg="set state to EnemyTurn"
May 17 22:05:25.353  INFO wanderer::systems::enemy: msg="enemy move"
May 17 22:05:25.353  INFO wanderer::systems::enemy: gs=State { transition: None, stack: [EnemyTurn], scheduled: None, end_next_loop: false }
May 17 22:05:25.353  INFO wanderer::systems::enemy: msg="setting state to PlayerTurn" gs=State { transition: None, stack: [EnemyTurn], scheduled: None, end_next_loop: false }
May 17 22:05:25.353  INFO wanderer::systems::enemy: msg="set state to PlayerTurn"
May 17 22:05:25.354  INFO wanderer::systems::player: gs=State { transition: None, stack: [PlayerTurn], scheduled: None, end_next_loop: false }
May 17 22:05:25.354  INFO wanderer::systems::player: msg="Up key pressed" <----- Didn't press any key
May 17 22:05:25.354  INFO wanderer::systems::player: action=Movement(1, 3)
May 17 22:05:25.354  INFO wanderer::systems::player: msg="player move or attack"
May 17 22:05:25.354  INFO wanderer::systems::player: msg="moving player"
May 17 22:05:25.354  INFO wanderer::systems::player: msg="setting state to EnemyTurn" change_state=true
May 17 22:05:25.354  INFO wanderer::systems::player: msg="set state to EnemyTurn"
@vildapavlicek vildapavlicek added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels May 17, 2021
@mockersf
Copy link
Member

this looks similar to #1700

@vildapavlicek
Copy link
Author

this looks similar to #1700

According to description it seems to be the same issue, just a bit different use case. Stuff recommended in that bug helped me work-around this issue.
Thanks.

@mockersf mockersf added A-ECS Entities, components, systems, and events A-Input Player input via keyboard, mouse, gamepad, and more and removed S-Needs-Triage This issue needs to be labelled labels May 17, 2021
@nicopap
Copy link
Contributor

nicopap commented Jan 31, 2023

Closed as duplicate of #1700

@nicopap nicopap closed this as not planned Won't fix, can't repro, duplicate, stale Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events A-Input Player input via keyboard, mouse, gamepad, and more C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

No branches or pull requests

3 participants