Is there a GIANT bug, or am I doing it wrong?

0 favourites
  • 9 posts
From the Asset Store
Be quick and choose whether the shown equation is right or wrong.
  • So here goes... I have 4 players in my game... and rather than doing the same exact events for all of them, I decided to do a "for" loop to get everything done in one... which I have done for mostly everything in my game.... however... here is my situation:

    My Player is setup with an instance called "Player" to which 1 - 4 is labeled just that... 1, 2, 3 and 4. My gamepads, being listed from 0 - 3 however (0 being the first) I need to change my for statement a bit, so this is what I have:

    System: For "" from 0 to 3

         Player: Player = loopindex +1 //Gets the proper instance

              Gamepad: Gamepad loopindex D-pad up is down

                  ?Do something

    Directional seems to work just fine for the most part.... But if I try this with buttons:

    System: For "" from 0 to 3

         Player: Player = loopindex +1 //Gets the proper instance

              Gamepad: Gamepad loopindex Button A is down

                  ?Do something

    It doesn't seem to work... or is sparatic, and very un-predictable... completely useless... or just skips over it. What am I doing wrong?

    If I spread it out (not in a "for" loop) it works flawlessly:

         Player: Player = 1 //Gets the proper instance

              Gamepad: Gamepad 0 Button A is down

                  ?Do something

         Player: Player = 2 //Gets the proper instance

              Gamepad: Gamepad 1 Button A is down

                  ?Do something

         Player: Player = 3 //Gets the proper instance

              Gamepad: Gamepad 2 Button A is down

                  ?Do something

         Player: Player = 4 //Gets the proper instance

              Gamepad: Gamepad 3 Button A is down

                  ?Do something

    I've fiddled with this now for two days... and rather than having an extra 300 events in my game, I would rather keep it down to 75 with the "for" loop for my inputs.

    Any help?

  • Nitro187, without seeing the real code it is hard to tell for sure, but it looks like the line " Player: Player = loopindex +1 //Gets the proper instance" is assigning a value to the Player instance variable, rather than "Picking" the correct instance... which would certainly give bazaar results because it would just be a random instance of Player, rarely the one you want.

    You want to use the System "Pick by evaluating Player" where the expression is "Player.Player=loopindex+1"

  • My expression was actually "Compare instance variable" and not set value.

    I'll try your method and report back, thanks.

  • I tried Pick by Evaluate, as well as Pick by comparison.... both do the exact same thing as what mine did..... directions work, buttons do not.

    Extremely strange....

    Any other ideas?

  • Another idea is System."Pick nth instance", assuming that Player1 is created first, then the 0th instance will always be Player1.

    A possibly better idea is to somehow use Families. Put each of the Player sprites in a single Family and call that family to do the certain events/actions.

    • Is this a single user with four players to play? Or is your game four players local? Four players online?

    And, I'm not sure about your bug. I agree with AllanR, would you mind showing us a CAPX or screenshot of that section of code?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The more I think about it, the more I want to say it's the order I have it.... thinking maybe Construct only works if you have it in this order:

    On Gamepad event -> Get player instance -> Do event

    But if that's the case, then I would still require 4 times the events, which leaves me back to where I am now.   So frustrated.

    I'll try the 'nth' instance in a bit and let you know.... I wish I could post my capx, or even a snippet... but I'm under an NDA, and can't show parts of the plugin that I'm using unfortunately.

  • I tried the nth instance, as well as a few more things.... for example, changing the order to this:

    System Every Tick

         System For "" from 0 to 3

              Gamepad : On Gamepad loopindex button A pressed

                   Pick Player where Player.Player = loopindex+1

                        Do event

    As well as a few more combinations of things... STILL not working.

    I'm almost POSITIVE this is a bug in Construct2 now.

  • No need for an "Every Tick". Your loop is already running every tick.

    Trying to use Triggers inside of Loops isn't going to work, if that is in fact what you are attempting to do.

    I'd suggest not running your Player Control Systems as a "For Loop". Instead, try a "For Each" loop. Something like this is what I assume you want: https://dl.dropboxusercontent.com/u/20459682/MultiplayerGamepad.capx

    "Trigger Once While True" is a looper's best friend.

  • I would suggest not tying your gamepad data directly into your player movement loop.

    I suggest using state based system instead.

    on 1 loop 0 to3

    check what ever state of gamepad loopindex

    --player.set button/direction based on gamepad

    on another loop 1to4

    if player.direction = "right" simulate control right

    There are three reasons for this design model over the style your doing.

    1. by using a state model it's usually ensured the input is valid and less likely to be interupted.

    2. it's controller agnostic. So you port to other control schemes, keyboard/mouse, touch analog, touch swipe....

    3. it's client prediciton ready for online. This one you likely don't care as much about. but it's good practice anyways.

    It's a little more overhead to get working, but the ROI is worth it if it's good design.

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