Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Hello,

I try to make the gamepad work, but i got some problems with it.
I hope you can help me out what i doing wrong.

What i did is the same like the keyboard check but then with the gamepad_button check.

like:

k_u = keyboard_check(global.input_key[input_U]) 
k_d = keyboard_check(global.input_key[input_D])

k_u gamepad_button_check(global.active_gamepad,global.input_pad[input_U])

k_d
gamepad_button_check(global.active_gamepad,global.input_pad[input_D])

ect.

Have i to change another script for make it work or doesn't work this like i did?

Thankyou.

Do you run the k_u = gamepad code after the keyboard code, always? Because then you'll overwrite the keyboard values with the gamepad values (a variable can only have one value at a time)

If you want to support using both a keyboard and a gamepad at once, try OR'ing them together:

k_u = keyboard_check(global.input_key[input_U]) || gamepad_button_check(global.active_gamepad,global.input_pad[input_U])
(1 edit)

Okay i see. If i start the debugger i see that the global.input_key got a array (9560E80), but the global.active_game,global.input_pad a unable to evaluate.

This is the error i got: 

ERROR in

action number 1

of Create Event

for object parent_menu:

trying to index a variable which is not an array

 at gml_Script_get_keys (line 17) -    k_u = keyboard_check(global.input_key[input_U]) ||gamepad_button_check(global.active_gamepad,global.input_pad[input_U])

############################################################################################

gml_Script_get_keys (line 17)

gml_Object_parent_menu_Create_0 (line 4) - get_keys()//Get once so that held keys won't instantly trigger press-but-not-held

gml_Object_obj_gguimenu_Create_0 (line 2)

gml_Object_obj_titlescreen_Create_0 (line 2)

What is the best way to make the gamepad works? Thankyou for your answer.

My guess is that global.input_pad is not initialized to a value before you try reading it - did you add it to init_input? You'll need to define a gamepad input for every action (U/D/L/R/A/B/C/ST/SL).

Deleted 1 year ago
(2 edits)

sorry to bother you again. Where i have to put the global.active_gamepad to make it working? I added the global.input_pad at init_input but still get a error because the active_gamepad i think.

Add it in the same script (init to a null value), also set it whenever you get a "gamepad" Async:System event (which is triggered whenever a gamepad is connected or disconnected). It's probably easiest to handle these events by putting a persistent "gamepad connection controller"object in the first room, which is a child of parent_active (so it can't be deactivated) - then it sticks around throughout the entire game without you having to put one in every room manually.