How do I reuse gamepad events for multiple players?

0 favourites
  • 8 posts
From the Asset Store
Very simple code without excess options (15 events for server and 11 events for client)
  • I'm trying to implement a multiplayer aspect to my game and I keep getting tripped up for a reason I hope can be remedied.

    As it stands, I have two event groups: the original player's gamepad events and a copy of the original player's gamepad events, which I tweaked to work with controller 2 and player 2 instead. This is fine and functional until I change player 1's events and forget to do the same with player 2.

    My question is: Is there a way I could wire this up so I only use one event group to control all players? I have the both players in a family, so replacing all the player 1 objects would be no problem, but I don't know how to make sure the controller event moves the right one (controller 0 only moves player 1, controller 1 only moves player 2).

    Thoughts?

  • One of the easiest way to do that would be to do all sprite/family actions with functions, and hook those functions to your gamepads events, and among the parameters, you'd send which player each function call should affect.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Would I still need multiple event groups for each player, then, to do four controllers? The way it works in my head is this:

    On gamepad (any number 0-3) A button pressed -> Call "jumpFunction" (gamepad.GamepadID)

    Instead of creating this event four times with gamepad numbers 0-3, I could do just the one and it would pass the gamepad number to the function and perform the action on whichever character has the matching gamepad ID. However, I don't know how to put "any" in the trigger event and it seems like I can't grab the current gamepad ID to pass to the function (gamepad.GamepadID needs a parameter).

    That's all totally theoretical and it's possible it just can't be done this way, but I thought I'd ask.

  • I don't do input in the way you do it, but perhaps if you check if the gamepad's ID/number is the same as the player ID/number like this condition: Gamepad.GamepadID(player.ID)

    You could always have at the top of an event, or group of events, a "For Loop" that runs from 0 to 3 (or whatever), and the check if the player ID and gamepad ID = loopindex("for loop")

  • Wrap your button pressing / axis testing in a for loop, starting from 0 to Gamepad.GamepadCount - 1, and use loopindex as your gamepad index.

    On gamepad loopindex A button pressed -> Call "jumpFunction" (loopindex)

    On "jumpFunction"

    +Pick player with instanceVar = Function.Params(0) --> Player jump

  • I ended up making a group of events with all the controller triggers set to "gamepad contID" and the functions pass contID, where contID is a local variable in the group with the gamepad ID assigned to it. I still had to make three copies for the other three players, but I only had to change that one local variable for them all to work.

    Is there any advantage (performance or otherwise) to using your method over mine? I almost think mine might be better in the way that I could easily tweak it to allow each player to customize their controller mappings.

  • You can allow customization using my method. At the end of the day, it's only a matter of preference. Personnally, I prefer to go as generic as I can, much less of a hassle when refactoring is needed.

    Here's how I would do it using a dictionnary (LocalStorage could also be used for persistence) :

    [attachment=0:8g4zcn5h][/attachment:8g4zcn5h]

    edit: I used triggers in this screenshot, I should have used the "is button index down" version instead, my bad !

  • Cool, I'll keep this bookmarked in case I decide to come back around to it. I'm just happy to have it functional for right now.

    Thanks for all the help!

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