Will not recognize that button is down after switching scenes

NobodyX

  • *
  • Posts: 1228
Sometimes the game will not recognize that a button is down after switching scenes. If I hold a directional button down to make my character keep walking as it moves from one scene to the next, then on the start certain scenes it will just not move until I let go of the button and re-press it.

I made it so that it draws a box while the "right" key is up, and unsurprisingly the box is drawn when this happens, meaning it does not recognize the key being held when it should and that it is definitely a bug.

It seems to happen on certain scenes but not others, but as far as I can tell it's completely random which scenes are affected.

Hectate

  • *
  • Posts: 4643
I believe this is a Flixel issue. I see to recall hearing people mention losing "down" key states when changing FlxStates.
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

NobodyX

  • *
  • Posts: 1228
So would that mean that it's unsolvable at this point then?

Hectate

  • *
  • Posts: 4643
I can't answer that myself - one of the devs would have to examine the codebase. I guess we'll just leave this post in the bug forum here for now.
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

Jon

  • *
  • Posts: 17524
You could work around it by storing the button's state in a game attribute and then somehow working that into your logic.

NobodyX

  • *
  • Posts: 1228
You could work around it by storing the button's state in a game attribute and then somehow working that into your logic.
I can't think of a way, because it would still have to be able to tell if the player had genuinely lifted the button or not. All I can think to do would be to make the player run automatically at the start of the level but then the game would be acting incorrectly if the player had actually lifted the button in between one scene ending and the other starting. Or am I not understanding something?

NobodyX

  • *
  • Posts: 1228
It's very important to me that this be fixed. As far as I can tell there's nothing I can do myself to fix it and it's impossible to create a work-around.

Can anyone help?

Joe

  • *
  • Posts: 2480
In the first frame of the new Scene, does the "control is [not down]" block register as true, regardless of whether or not the button was down before the transition?

NobodyX

  • *
  • Posts: 1228
I just checked and, when the bu occurs, "control is [up]" registers as true until you release and re-press the button.

But I just noticed some funny things:

The bug can occur with some keys and not others within one scene-switch. I had it set to that it draws on the screen whether "shoot" is down and the same with "right," and sometimes the scene will switch and it will stop recognizing "shoot" but your guy will continue walking as it should, or sometimes it will recognize that you are holding "shoot" but will think "right" is not being held.

Also, if you walk off one scene and your guy will appear off of the ground air at the start of the next, it will not register "right" being down until your character hits the ground, then it will start walking and start noticing that the key is down. This is strange because I am not checking for anything more complicated than whether the button is down.

Joe

  • *
  • Posts: 2480
This definitely sounds like a Flixel issue. If that's the case, the only workaround I can think of is to create both areas in the same Scene and simply teleport between them. Lots of 3D games do this.

NobodyX

  • *
  • Posts: 1228
Wow, seriously? This would require a ridiculous amount of work and I'd have to basically recreate every level in the game.

I am still hopeful because of the last thing I mentioned in my last post. What could it be about the character landing that it starts recognizing the key properly? Maybe there's some way I could know what it is that does that, then make whatever it is that happens happen at the start of each scene?

Joe

  • *
  • Posts: 2480
No idea. Jon or one of the developers familiar with the engine might know better. Maybe there's some code we can salvage from within Flixel that refreshes the key states upon a collision.

Also, out of curiosity, does the [control was pressed] block also register as false when the Scene first begins? If anything, I would have expected the bug to be that the engine thinks the key was "just pressed" when the Scene begins.

Greg

  • *
  • Posts: 1260
I did a bit of testing and found the following (checking for the 'X' key) -

1) Scenario 1 - holding the X key alone and changing scenes, the next scene knew that the key was down
2) Scenario 2 - holding the Z key, and then also holding the X key, after the scene change it knew that X was down
3) Scenario 3 - holding the X key, and then also holding the Z key, after the scene change the fact that the X key was down was lost

Assuming this is a fair test, it looks like only the last key to be pressed will still be reported after a scene change.

NobodyX

  • *
  • Posts: 1228
Actually it turns out that it's not when the character lands, it's only that it starts working properly a short amount of time after the scene loads which coincidentally happened to be the same amount of time it would take for the player to hit the ground.

Quote
Also, out of curiosity, does the [control was pressed] block also register as false when the Scene first begins? If anything, I would have expected the bug to be that the engine thinks the key was "just pressed" when the Scene begins.
I'll check right now.

Legendary Hoamaru

  • *
  • Posts: 1088
It actually looks like an easy fix.  I noticed that code yesterday.  Input is cleared on scene switch  (in the cleanup method of GameState) with FlxG.resetInput();

Couldn't we create a toggle for this?