Passing input from multiple players to functions

Just started using Construct 2? Post your questions here

Post » Mon Dec 29, 2014 4:07 pm

I am trying to create a local multiplayer game in which 2 players can provide input via keyboard/gamepads

The game will eventually be fairly complex and the players will interact with various other sprites and can take a number of different states. The players will be made up of several sprites (using a container). To keep things organised I would like to change the player state based on keyboard input and then have the state changes call functions which trigger actions. These actions may impact certain sprites the players are made up of as well as the sprites the players are interacting with.

In the simple CAPX below the layout with one player works fine, but the layout with two players is resulting in one player state overriding the other. Any suggestions appreciated.

s000.tinyupload.com/?file_id=69883725359287767242
B
12
S
2
G
1
Posts: 26
Reputation: 892

Post » Mon Dec 29, 2014 4:33 pm

I am not running the beta but latest stable, so I cant look.

If a state is overriding another, it would not be illogical to say that one of the inputs is addressing the wrong player object.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Mon Dec 29, 2014 5:09 pm

See my event sheet below. I'm trying to support 2 or more players (using gamepads).

eventsheet.gif


Have uploaded an updated CAPX fie for anyone using r192.

s000.tinyupload.com/?file_id=00649642362768732583
You do not have the required permissions to view the files attached to this post.
B
12
S
2
G
1
Posts: 26
Reputation: 892

Post » Mon Dec 29, 2014 5:24 pm

I am using r190.

But I think I see an issue there.

event 4, that foreach, will accept the input given on that controller for the player it currently "for eaches"

Separate it in individual events.

ie, actually use:

event
Gamepad Player.0 etc
action
call move down (player 0)

event
Gamepad Player.1 etc
action
call move down (player 1)


etc

Something like those.

You will end up with lots of single events, one for each controller action.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Mon Dec 29, 2014 5:35 pm

I was hoping to avoid creating separate events for each player's controller actions as there will be a large number of inputs (button combinations etc..). Is there any way I can dynamically support 1 to 4 players without having to create separate events for each controller?
B
12
S
2
G
1
Posts: 26
Reputation: 892

Post » Mon Dec 29, 2014 5:54 pm

I have made several games with controllers, even a few with more controllers ... but I always had to make separate events.

You could have some groups with player actions/functions/controls disabled, and have an event for each controller which activates them.

if gamepad.0 A is pressed activate group X
if gamepad.1 A is pressed activate group Y

or,

if gamepad.0 A is pressed, set players to 1
if gamepad.1 A is pressed, set players to 2

and use the players value as a trigger for the loops for actions/functions etc.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Tue Dec 30, 2014 5:18 pm

You might use the Gamepad ID to pick the correct player.UID.

For instance, if your player objects UIDs are 4 and 5, controlled by Gamepads 0 and 1, you could just pass the Gamepad ID whenever any button is pressed to the function and pick the instance Gamepad ID + 4 (4 for Gamepad 0 and 5 for Gamepad 1).

Can't check it now, cause I have only one gamepad at work, but I believe it should work...
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
20
S
6
G
3
Posts: 624
Reputation: 3,750


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 4 guests