GameMaker Turning off gamepad?

  • Thread starter Deleted member 16767
  • Start date
Status
Not open for further replies.
D

Deleted member 16767

Guest
I've searched for a string that can do this but it looks like there is none. I'd like to make gamepad an optional pick in my games settings menu.
 
D

Deleted member 16767

Guest
I tried doing the if and else statement. It's not working. I want to disable the gamepad in settings because it is interfering with my custom made left stick movements, which makes A and D not working. The user has to unplug the gamepad to move with A and D.

I made the index of the image follow the mouse cursor because I couldn't make the players image index flip any other way when moving with left stick.
 

jujubs

Member
Have you tried using an "or" statement?
like
Code:
x = keyboard_check(vk_right) - keyboard_check(vk_left) || gamepad_axis_value(0, gp_axislh);
y = keyboard_check(vk_down) - keyboard_check(vk_up) || gamepad_axis_value(0, gp_axislv);
 

kburkhart84

Firehammer Games
Can you show us the code you tried when trying the if/else statements? That's usually a good solution to this kind of thing.
Code:
if(using_gamepad)
{
    xDir = gamepad_axis_value(0, gp_axislh);
}
else
{
    xDir = keyboard_check(vk_right) - keybaord_check(vk_left)
}
I don't think the logic in that code is exactly right, but it should give you an idea what to do.
 
D

Deleted member 16767

Guest
Code:
switch_image_left = hspeed <=-1
switch_image_right = hspeed >=1


//Making it recognize the left stick as moving the player.
if gamepad_is_connected(0)
{
var haxis = gamepad_axis_value(0, gp_axislh);
var vaxis = gamepad_axis_value(0, gp_axislv);
direction = point_direction(0, 0, haxis, vaxis);
speed = point_distance(0 ,0, haxis, vaxis) * 8;
}


//The player flips image index depending on where the mouse cursor is.

if gamepad_is_connected(0)
{

if switch_image_left
{
window_mouse_set(obj_Player_Monk.x-10000, y)
image_xscale = -1 
}

if switch_image_right
{
window_mouse_set(obj_Player_Monk.x+10000, y)
image_xscale = 1 
}
Code:
//Step Event for directional images on mouse cursor direction.
facing = floor(point_direction(x, y, mouse_x, mouse_y));
 

kburkhart84

Firehammer Games
I don't see any code there where you have a variable that is set to determine whether the player actually wants to use the gamepad or not. You have one if statement that just says if the gamepad is connected, to set the direction of the sprite based on the direction of the left stick axes. Then you have another if statement that says if you have a gamepad, you are using the mouse to set the xscale of the image...I'm not sure why you want to have the mouse code inside that if statement because you aren't using the gamepad in that second if statement, though it won't execute if there is no gamepad connected. I also note that you are missing a closing bracket on the second "if gamepad_is_connected(0)" statement. You need to always have a closing bracket for each opening bracket(maybe you just forgot to include it when you copy/pasted your code here).

I see basically issues with your logic. The first issue with the logic is that you are checking part gamepad # 0. There could easily be multiple gamepads connected, and none of them would have index 0 if they aren't XInput devices. If you want to do proper support, you will need to loop through all the gamepad indices and verify which one the player wants to use(or somehow combine them as if they were one device in your code).

The second issue is that you are using the axis_value functions to set the direction assuming you find a gamepad, right? But if you don't have a gamepad there, I don't see you setting the direction based on the keyboard. Assuming the logic of the if statement were correct in the first place, you would need to have an else statement there which would check some keyboard keys, and set the direction and speed accordingly, maybe using the arrows, or whatever keys you wanted.
 
D

Deleted member 16767

Guest
I can make it a variable and just turn it off. It has to be a global variable. I played around with it a bit on a cinematic in the game and it works. But isn't variables restricted to one line code segments?

@kburkhart84 I'm using the mouse for now, but I will be using an object later.
 
A variable being restricted to one line code segments? What does that even mean? I'd suggest really getting to know the basics of GM programming (i.e. instance vs object/variables/accessing instance variables/etc) in order to fix this problem.
 
Status
Not open for further replies.
Top