Multiple, dynamic gamepads

Discussion and feedback on Construct 2

Post » Sun Nov 09, 2014 3:04 pm

Hi folks, I'm running into a brick wall here and I hope some of the more experienced C2 users can give me some insight into how to fix this issue. Here's my situation:

- Four-player co-op game, using keyboard and/or gamepads.
- Character selection screen before the game kicks off.
- In this screen, I want to give players the chance to pick up any gamepad and press A to join in. I want them to be assigned a player number based on the order in which they join.

I've got the game working so that player numbers are assigned based on the controller number, so P1 can be keyboard, P2 can be gamepad(0), P3 is gamepad(1), etc. Or P1 is gamepad(0), P2 is gamepad(1) and so on. All of the controls are set up so that it accepts input from any source, then passes that input along to a set of generic functions that actually make the players move.

The trouble is, there's no generic "On any gamepad, any button pressed" event, nor is there a way to record a controller number when a button is pressed. This means that players will need to join the game in the order that gamepads are assigned by the OS, not the order in which they press the A button. This is what I'm trying to avoid.

I'd like to use the logic "When Up is pressed on controller(Player/ControllerNumber), move Sprite(Player/ControllerNumber) up", but I can't figure out how to match a player to a controller in a dynamic way.

I hope this makes sense, and I hope someone can assist!
B
57
S
15
G
11
Posts: 912
Reputation: 12,626

Post » Sun Nov 09, 2014 3:34 pm

Hello GeometriX

I ran into the same problems as you and I got a solution working, maybe not the better :)

You create your players with an ID (starting at 0 for first player) and you assign this player an input method (like Keyboard or Gamepad)

Image

You loop over all of you players, and test the input corresponding to the input method and the gamepad number and you save the input in a Player variable called "Input" using "setbit" like in this tutorial: https://www.scirra.com/tutorials/915/multiplayer-tutorial-3-real-time-game/page-6

For gamepad
Image

For keyboard
Image

In the same loop you get the input using the same input variable and the "getbit" expression

Image

And voilà :]
You do not have the required permissions to view the files attached to this post.
B
6
S
2
Posts: 24
Reputation: 737

Post » Mon Nov 10, 2014 5:56 pm

You could create 4 events (on gamepad 1 pressed, 2, 3, etc ) that checks which "start" button was pressed, then assign that player an ID. Also make a variable that gets assigned the gamepad number who's button was pressed.

Then create one function for all of your inputs. You pass the button that was pressed (gamepad.lastbutton) And you pass the gamepad number that presseed it (the variable from before)

there fore each time a button is pressed, the function uses who pushed it and which button, then updates the associated player with whatever he's supposed to do. (Pick by evalulate, player.ID = function.param(0))

then you only have one function, to handle all player movement etc for all players, thus only having to write it once.
B
88
S
44
G
16
Posts: 1,009
Reputation: 17,971

Post » Mon Nov 10, 2014 7:36 pm

justifun wrote:Also make a variable that gets assigned the gamepad number who's button was pressed.

That's the exact problem. I've already got controls working across all gamepads and keyboard for pre-selected controller/player pairs, but there's no "Gamepad.Number" or whatever expression. That's why I can't figure how to dynamically assign the controller.

EDIT: Sorry, I misunderstood your first point. I've done that now which is great. Assigned controllers initially is now resolved. But this still doesn't solve the issue in your second paragraph "And you pass the gamepad number that presseed it (the variable from before)". There's no way to extract that from a gamepad event without having events for every single gamepad and passing along the variable manually.

Thanks for your reply as well, @RootKernel, but, unless I'm missing something, it doesn't help solve my problem.

Really what would solve all of my issues is if there was an action "On any gamepad pressed" (maybe a set of actions, for buttons/sticks/etc.), and a Gamepad.Number expression that reads which gamepad triggered the current event. Then I could bundle all of my controls and assignments into just a few events.

@Ashley, any thoughts on this? I know that there probably is a way around my problem, but I can't quite manage to bend my brain there. Having a couple of conditions and an expression would be magical.
B
57
S
15
G
11
Posts: 912
Reputation: 12,626

Post » Mon Nov 10, 2014 8:23 pm

Ooookay, I get it now. I was way over-thinking this whole thing, which was causing my to misinterpret what both of you were saying.

Thanks so much @RootKernel and @justifun, I really appreciate your help!
B
57
S
15
G
11
Posts: 912
Reputation: 12,626


Return to Construct 2 General

Who is online

Users browsing this forum: AlexiarTW and 10 guests