GML gamepad detection problem at room change gms 2

D

diester

Guest
Hello to all and all, before all sorry for my English I use a translator.
I come to you for help, I use the joystick detection function :

https://docs.yoyogames.com/index.ht... and other controls/keyboard input/index.html

and even follow the tutorial "gamepads" in game maker studio 2.
but the detection does not happen when I change rooms. I am obliged to disconnect and reconnect the joystick with each change of room for which player is displayed..
I do not know how to make the permanent detection of one part to another. who can help me please ?
thanks everyone
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Okay, I'm afraid I'm a bit confused... you ask about joystick detection then link to the KEYBOARD section of the 1.4 manual. Then you mention the gamepads tutorial and GMS2... :(

So, some questions!

1) What version of GameMaker are you using? GM:S 1.4, or GMS2?
2) Are you using the GAMEPAD functions or the JOYSTICK functions? The joystick functions are obsolete in GMS2
3) Can you show the code or explain how you are detecting the controller?
 
D

diester

Guest
sorry if I made a mistake in my request.
in fact I use game maker studio 2.

the keyboard system for the menu (because with the joystick the movement is too fast) > I was wrong link sorry
I did the test with an analog gamepad and a digital one.
here is the detection code in obj_Control:

in Acync :
Code:
// Code de débogage pour que vous puissiez voir quel événement a été
// déclenché et le pad qui lui est associé.
show_debug_message("Event = " + async_load[? "event_type"]);
show_debug_message("Pad = " + string(async_load[? "pad_index"]));

// Analyse la mappe async_load pour voir quel événement a été déclenché
switch(async_load[? "event_type"])
{
 
// Une manette de jeu a été découverte case "gamepad discovered":
// Récupère la valeur d'index du pad à partir de la carte async_load
    var pad = async_load[? "pad_index"];
// Définit la "deadzone" pour l'axe
  gamepad_set_axis_deadzone(pad, 0.5);
  // Définit le "seuil" pour les déclencheurs
  gamepad_set_button_threshold(pad, 0.1);
 // Vérifie si une instance est associée à pad index
  if !(instance_exists(player[pad]))
    {
    // Créer un objet joueur et lui attribuer un numéro de pad
    var _xx = 64 + random(room_width - 128);
    var _yy = 64 + random(room_height - 128);
    player[pad] = instance_create_layer(_xx, _yy, "instances", obj_player);
    with (player[pad])
      {
      image_index = instance_number(object_index) - 1;
      pad_num = pad;
      }
    }
  break;
// Gamepad a été supprimé ou désactivé
case "gamepad lost":
  // Obtenir l'index du pad
  var pad = async_load[? "pad_index"];
  // Recherchez une instance de joueur associée au pad et supprimez-la.
  if (instance_exists(player[pad]))
    {
    with (player[pad])
      {
      instance_destroy();
      }
    // Définit le tableau du contrôleur sur "noone" afin qu'il détecte un nouveau pad en cours de connexion
    player[pad] = noone;
    }
  break;
}
in Step :

Code:
//manette simple sans joystick numérique
var h_move = gamepad_axis_value(5, gp_axislh);
var v_move = gamepad_axis_value(5, gp_axislv);

if ((h_move != 0) || (v_move != 0))
    {
    x += h_move * 4;
    y += v_move * 4;
    }


//manette avec double joystick numérique
var h_move = gamepad_button_check(4, gp_padr) - gamepad_button_check(4, gp_padl);
var v_move = gamepad_button_check(4, gp_padd) - gamepad_button_check(4, gp_padu);

if ((h_move != 0) || (v_move != 0))
    {
    x += h_move * 4;
    y += v_move * 4;
    }
in Creat :

Code:
for (var i = 0; i < 12; i++;)
{
player[i] = noone;
}

// Définir les propriétés de dessin
draw_set_font(fnt_scores);
draw_set_colour(c_white);

gamepad_set_axis_deadzone(4, 0.4);  
gamepad_set_button_threshold(4, 0.1);

gamepad_set_axis_deadzone(5, 0.5);  
gamepad_set_button_threshold(5, 0.1);
 
Last edited by a moderator:

Nocturne

Friendly Tyrant
Forum Staff
Admin
Okay, the issue here is that the Async event will only be triggered when:

1) The game starts.
2) A pad is added.
3) A pad is removed.

It won't be triggered for every room change, which means your code will only run once when the game is started. What you need to do is remove all the code for creating the player from the Async event and ONLY have the async event check for gamepads and then store the connected pads in a global variable or array. Then, from a controller object, you create the player and assign a pad ID from the global variable/array based on the connected pads initially detected.
 
D

diester

Guest
Okay, the issue here is that the Async event will only be triggered when:

1) The game starts.
2) A pad is added.
3) A pad is removed.
this is the problem because the game is starting (room 0 -> menu) I control with the keyboard "on this room if I put the object control player appears and works but if on the menu I click start the game when I arrive in the room of the game 5 there is nothing, I must unplug and reconnect the pad, yet the pad is already connected, so the player should be present.
here is the arboressence of the rooms.



the fact of removing the player when the pad is disconnect I can remove it is not a problem but does not change the annoyance.

I do not see how I should do in your description, I have to do the detection code (Acync) in a script?
 

Xrqton

Member
Okay, the issue here is that the Async event will only be triggered when:

1) The game starts.
2) A pad is added.
3) A pad is removed.

It won't be triggered for every room change, which means your code will only run once when the game is started. What you need to do is remove all the code for creating the player from the Async event and ONLY have the async event check for gamepads and then store the connected pads in a global variable or array. Then, from a controller object, you create the player and assign a pad ID from the global variable/array based on the connected pads initially detected.
Thanks a lot for the tip, awesome.
 
Top