"For Each" Causing Problems

0 favourites
  • 9 posts
  • Problem Description

    I'm trying to control a physics sprite with a gamepad. I reached a point where I started working on an entirely different part of the game, and suddenly problems, where everything was previously working perfectly, started popping up! If seemingly any "For Each" event was used in combination with my code to change the angle of the physics sprite, the sprite will always try to aim to the right or 0 degrees. It's meant to still remain in the general direction it was facing... not return to 0 degrees.

    If I disable the "For Each" code, it works as intended. I thought it was because my original "For Each" contained the player sprite, so I changed it so it was completely disconnected, and the same error occurred. Tried on multiple devices running 216.

    Attach a Capx

    https://copy.com/puXdKs9PCtrA0Orr

    Description of Capx

    Capx shows a very simple game producing the problem I'm having.

    Steps to Reproduce Bug

    • Play Game with GamePad connected
    • Touch a button and move the right stick
    • Note that the player sprite will rotate, but always return to 0 degrees when you release the stick
    • Close the game, disable the "For Each" event(s), and play the game again
    • Note that the player sprite will rotate and will not try to aim back to 0 degrees when the stick is released

    Observed Result

    The Player sprite will always try to aim towards 0 degrees

    Expected Result

    The Player sprite should remain towards it's last angle, or spin

    Affected Browsers

    • Chrome: (YES)
    • FireFox: (YES)
    • Internet Explorer: (YES)

    Operating System and Service Pack

    Windows 7 and Windows 10

    Construct 2 Version ID

    Release 216

  • I don't have a joystick, but I can't get the same result if I use keyboard instead. What are the values returned for the joystick axis when not pressing anything?

  • R0J0hound If the "For Each" is on, when the joystick is released, it reverts back to 0. Then again, the GamePad object doesn't have any values, so I had to gain that info by setting a variable to:

    angle(0,0,Gamepad.Axis(0,2),Gamepad.Axis(0,3))

    as I'm dealing with the right stick. Just did a quick test, however, and it appears to work fine for the left stick. Doesn't help me though, as I'll be using both sticks.

    Also tried this with the latest beta, and it's still a problem.

  • Sounds like it may be an issue with the gamepad plugin perhaps. The issue of the "for each" effecting the other events possibly could be related to an "or" bug reported about a week ago.

  • You are using "loopindex" in the "Gamepad loopindex Right analog axis" action! "For each" is changing loopindex, so it is changing the Gamepad index unintentionally.

  • blackhornet Ahh... is this a bug then? I use loopindex to base it off of the number of gamepads... I wanted to save myself repeating the code 4 times.

  • If you give your loop a name, loopindex("gamepad"), it will work fine.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • blackhornet Thanks a lot ☺

  • It's not valid to use loopindex outside of a loop, so closing as not a bug. As it is, you'll be using whatever loopindex value was left behind by the last loop.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)