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

Get help using Construct 2

Post » Sun Feb 02, 2014 7:08 pm

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?Nitro1872014-02-02 19:13:08
B
47
S
15
G
3
Posts: 201
Reputation: 4,625

Post » Sun Feb 02, 2014 7:53 pm

@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"AllanR2014-02-02 20:01:34
B
97
S
34
G
20
Posts: 438
Reputation: 17,790

Post » Sun Feb 02, 2014 9:06 pm

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

I'll try your method and report back, thanks.
B
47
S
15
G
3
Posts: 201
Reputation: 4,625

Post » Sun Feb 02, 2014 9:29 pm

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?
B
47
S
15
G
3
Posts: 201
Reputation: 4,625

Post » Sun Feb 02, 2014 11:08 pm

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?
B
20
S
4
G
1
Posts: 185
Reputation: 2,563

Post » Mon Feb 03, 2014 12:27 am

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.
B
47
S
15
G
3
Posts: 201
Reputation: 4,625

Post » Mon Feb 03, 2014 1:28 am

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.
B
47
S
15
G
3
Posts: 201
Reputation: 4,625

Post » Mon Feb 03, 2014 8:05 am

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.TL222014-02-03 08:08:13
B
94
S
34
G
8
Posts: 314
Reputation: 11,199

Post » Mon Feb 03, 2014 8:14 am

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.



B
90
S
18
G
9
Posts: 2,455
Reputation: 15,028


Return to How do I....?

Who is online

Users browsing this forum: Exabot [Bot], Kin, mikehive, ratboy3, tinhofiel and 38 guests