0 Favourites

Passing input from multiple players to functions

  • 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

  • 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.

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

    [attachment=0:3cevwxj5][/attachment:3cevwxj5]

    Have uploaded an updated CAPX fie for anyone using r192.

    s000.tinyupload.com/?file_id=00649642362768732583

  • 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.

  • 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?

  • 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.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • 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...

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