KyleRansford
Member
I have my game setup where if there are more than 1 player, they can each use a controller. But, how would I "reserve" a controller slot for player 1? Since the way I currently have it working is, that in 1 player mode, the 1st player can use either the keyboard OR a controller. But, because of the way I have it working, in order for the 2nd player to be able to play, there needs to be at least 2 controllers connected so that both Slot 0 and Slot 1 are filled, so the 2nd player can use the controller to control their player. (Even if Player 1 doesn't use their controller).
How could I make it where I only need 1 controller for 2 player mode? But, "reserve" Slot 0 for Player 1 if they later connected a controller? Hopefully I'm explaining this right. Basically, how I "act like" there's a controller in Slot 0, but there's really not, but with only 1 controller connected it connects to Slot 1, not Slot 0, so the 2nd player can use it. But, if player 1 did want to connect a controller for them, it would then connect to the "reserved" controller slot 0.
Here's my Input code for Player 1 and Player 2 and here a reference on how I use it. For instance, if I wanted a player to shoot a bullet:
Both of these lines of code are in the player object's Step Event.
Code for o_input (Player 1's input method)
Create (same for player 2):
Begin Step (same for player 2):
User Event 0:
Code for o_inputP2 (Player 2's input method) The same as Player 1's, except no keyboard controls.
How could I make it where I only need 1 controller for 2 player mode? But, "reserve" Slot 0 for Player 1 if they later connected a controller? Hopefully I'm explaining this right. Basically, how I "act like" there's a controller in Slot 0, but there's really not, but with only 1 controller connected it connects to Slot 1, not Slot 0, so the 2nd player can use it. But, if player 1 did want to connect a controller for them, it would then connect to the "reserved" controller slot 0.
Here's my Input code for Player 1 and Player 2 and here a reference on how I use it. For instance, if I wanted a player to shoot a bullet:
Both of these lines of code are in the player object's Step Event.
GML:
// Fire laser for Player 1
if o_input.action_one_pressed_ {
audio_play_sound(a_laser, 1, false);
event_user(14);
}
// Fire laser for Player 2
if o_inputP2.action_one_pressed_ {
audio_play_sound(a_laser, 1, false);
event_user(14);
}
Create (same for player 2):
GML:
GET_INPUT = 0;
event_user(GET_INPUT);
GML:
event_user(GET_INPUT);
GML:
Xbox_One_Controller_1_ = 0; // Slot 0
// Movement
right_ = keyboard_check(vk_right) or gamepad_axis_value(Xbox_One_Controller_1_, gp_axislh) > 0.50 or gamepad_button_value(Xbox_One_Controller_1_, gp_padr);
left_ = keyboard_check(vk_left) or gamepad_axis_value(Xbox_One_Controller_1_, gp_axislh) < -0.50 or gamepad_button_value(Xbox_One_Controller_1_, gp_padl);
up_ = keyboard_check(vk_up) or gamepad_axis_value(Xbox_One_Controller_1_, gp_axislv) < -0.40 or gamepad_button_value(Xbox_One_Controller_1_, gp_padu);
down_ = keyboard_check(vk_down) or gamepad_axis_value(Xbox_One_Controller_1_, gp_axislv) > 0.40 or gamepad_button_value(Xbox_One_Controller_1_, gp_padd);
right_pressed_ = keyboard_check_pressed(vk_right) or gamepad_button_check_pressed(Xbox_One_Controller_1_, gp_padr);
left_pressed_ = keyboard_check_pressed(vk_left) or gamepad_button_check_pressed(Xbox_One_Controller_1_, gp_padl);
up_pressed_ = keyboard_check_pressed(vk_up) or gamepad_button_check_pressed(Xbox_One_Controller_1_, gp_padu);
down_pressed_ = keyboard_check_pressed(vk_down) or gamepad_button_check_pressed(Xbox_One_Controller_1_, gp_padd);
// Action Keys
menu_pause_pressed_ = keyboard_check_pressed(vk_enter) or gamepad_button_check_pressed(Xbox_One_Controller_1_, gp_start);
pause_pressed_ = keyboard_check_pressed(vk_shift) or gamepad_button_check_pressed(Xbox_One_Controller_1_, gp_select);
action_one_ = gamepad_button_check(Xbox_One_Controller_1_, gp_face3) or keyboard_check(ord("D"));
action_two_ = gamepad_button_check(Xbox_One_Controller_1_, gp_face2) or keyboard_check(ord("A"));
action_three_ = gamepad_button_check(Xbox_One_Controller_1_, gp_face4) or keyboard_check(ord("W"));
action_four_ = gamepad_button_check(Xbox_One_Controller_1_, gp_face1) or keyboard_check(ord("S"));
action_one_pressed_ = gamepad_button_check_pressed(Xbox_One_Controller_1_, gp_face3) or keyboard_check_pressed(ord("D"));
action_two_pressed_ = gamepad_button_check_pressed(Xbox_One_Controller_1_, gp_face2) or keyboard_check_pressed(ord("A"));
action_three_pressed_ = gamepad_button_check_pressed(Xbox_One_Controller_1_, gp_face4) or keyboard_check_pressed(ord("W"));
action_four_pressed_ = gamepad_button_check_pressed(Xbox_One_Controller_1_, gp_face1) or keyboard_check_pressed(ord("S"));
action_one_released_ = gamepad_button_check_released(Xbox_One_Controller_1_, gp_face3) or keyboard_check_released(ord("D"));
action_two_released_ = gamepad_button_check_released(Xbox_One_Controller_1_, gp_face2) or keyboard_check_released(ord("A"));
action_three_released_ = gamepad_button_check_released(Xbox_One_Controller_1_, gp_face4) or keyboard_check_released(ord("W"));
action_four_released_ = gamepad_button_check_released(Xbox_One_Controller_1_, gp_face1) or keyboard_check_released(ord("S"));
GML:
Xbox_One_Controller_2_ = 1; // Slot 1
// Movement
right_ = gamepad_axis_value(Xbox_One_Controller_2_, gp_axislh) > 0.50 or gamepad_button_value(Xbox_One_Controller_2_, gp_padr);
left_ = gamepad_axis_value(Xbox_One_Controller_2_, gp_axislh) < -0.50 or gamepad_button_value(Xbox_One_Controller_2_, gp_padl);
up_ = gamepad_axis_value(Xbox_One_Controller_2_, gp_axislv) < -0.40 or gamepad_button_value(Xbox_One_Controller_2_, gp_padu);
down_ = gamepad_axis_value(Xbox_One_Controller_2_, gp_axislv) > 0.40 or gamepad_button_value(Xbox_One_Controller_2_, gp_padd);
right_pressed_ = gamepad_button_check_pressed(Xbox_One_Controller_2_, gp_padr);
left_pressed_ = gamepad_button_check_pressed(Xbox_One_Controller_2_, gp_padl);
up_pressed_ = gamepad_button_check_pressed(Xbox_One_Controller_2_, gp_padu);
down_pressed_ = gamepad_button_check_pressed(Xbox_One_Controller_2_, gp_padd);
// Action Keys
pause_pressed_ = gamepad_button_check_pressed(Xbox_One_Controller_2_, gp_start);
menu_pause_pressed_ = gamepad_button_check_pressed(Xbox_One_Controller_2_, gp_select);
action_one_ = gamepad_button_check(Xbox_One_Controller_2_, gp_face3);
action_two_ = gamepad_button_check(Xbox_One_Controller_2_, gp_face2);
action_three_ = gamepad_button_check(Xbox_One_Controller_2_, gp_face4);
action_four_ = gamepad_button_check(Xbox_One_Controller_2_, gp_face1);
action_one_pressed_ = gamepad_button_check_pressed(Xbox_One_Controller_2_, gp_face3);
action_two_pressed_ = gamepad_button_check_pressed(Xbox_One_Controller_2_, gp_face2);
action_three_pressed_ = gamepad_button_check_pressed(Xbox_One_Controller_2_, gp_face4);
action_four_pressed_ = gamepad_button_check_pressed(Xbox_One_Controller_2_, gp_face1);
action_one_released_ = gamepad_button_check_released(Xbox_One_Controller_2_, gp_face3);
action_two_released_ = gamepad_button_check_released(Xbox_One_Controller_2_, gp_face2);
action_three_released_ = gamepad_button_check_released(Xbox_One_Controller_2_, gp_face4);
action_four_released_ = gamepad_button_check_released(Xbox_One_Controller_2_, gp_face1);