How do I make a gamepad event for more than one object

Get help using Construct 2

Post » Fri Oct 10, 2014 9:24 am

I've been trying to make an "universal" event that would select an instance from a family based on the index of the gamepad. But the gamepad object seems unable to know it's own index value based on input.

My idea was to: On something done on any gamepad; pick instance based on gamepad index value; then do something for that instance.
However every gamepad input is required to be a predetermined index value.

Why isn't there a general expression to know which gamepad made the input? It would make setting up multiple players 4 times more efficient.

Unless there is a way to do this? in which case: help? D:
B
43
S
12
G
6
Posts: 446
Reputation: 6,807

Post » Fri Oct 10, 2014 5:51 pm

really interested in this
B
43
S
12
G
6
Posts: 446
Reputation: 6,807

Post » Wed Oct 15, 2014 7:07 am

One solution ( and its probably not the cleanest) - is to great a single layout that you can reuse in any game you make in the future.

Create 4 events to handle the pressing of the start button for each game pad
eg:
if gamepad 0 presses start - call function "spawn player" "0"
player.owner = 0
if gamepad 1 presses start - call function "spawn player " "1"
player.owner = 1
etc.

Then create a series of events to check which button was pressed for each controller
eg:
if gamepad button is down (Gamepad = 0), button = A) -> Call another function called "Shoot", "0"

etc, and do this for every button combination.

Once you set this up once, all you have to do is create events for each new game you create that has a function that matches the button press function call from your "input" layout.

so. on function "shoot" "0"
pick player.owner = function.param(0) -> do whatever should happen here

if you did on function "shoot" "1" it would do the shoot event for player 1 instead

I hope this all makes sense, im pretty tired right now.

But basically you only need to setup on layout with a series of if statements to handle each gamepad and button. Have them call a generic function EG: jump, shoot etc. And pass the gamepad index number as a parameter, so that you only need to have one function per button, which will determine which player to do the action to based on the gamepad index that initiated it.

once you set it all up once, you can simply import that layout to your next game, and include it in your main event sheet, and it will be all ready to go.
B
90
S
44
G
17
Posts: 1,012
Reputation: 18,527


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 32 guests