Windows Down on left analogue stick (Axis_lv) to change instance.

Liam Earles

Member
Okay, so when I change instance by pressing down on both arrow keys, and the D-Pad on the controller, they both work fine. But with the Analogue stick, it's a whole different story. So I have an object that can do cartwheels which moves by changing the instance into a different object when holding down, but when I have the instance changed by holding down on the analogue stick, it wouldn't move until I release the right analogue stick.
Here's the code for the controller step:
Code:
if gamepad_axis_value(0, gp_axislv) > 0
{
          keyboard_key_release(vk_down)
          gamepad_button_check_released(0,gp_padd)
}
Here's the code for the Controller's create step:
Code:
gamepad_set_axis_deadzone(0, 0.7)
gamepad_set_button_threshold(0, 0.1)
gamepad_button_value(0,gp_face1)
Here's the code for the character in Idle holding down on the left analogue stick:
Code:
if gamepad_axis_value(0,gp_axislv) > 0
{
keyboard_key_press(vk_down)
keyboard_key_release(vk_down)
instance_change(AvaCartwheelTechnique, true)
}
And here's the code for the character doing the cartwheel action:
Code:
if gamepad_axis_value(0,gp_axislv) > 0
{
keyboard_key_press(vk_down)
keyboard_key_release(vk_down)
instance_change(Ava, true)
}
Let me know how to fix this because I was trying to figure this out for almost 4 - 5 weeks and I need it fixed. Thanks!
 

TheouAegis

Member
keyboard_key_press(vk_down)
keyboard_key_release(vk_down)
I was going to say this doesn't work, but by jove you taught me something new! Not knowing about needing keyboard_key_release would have left me scratching my head over keyboard_key_press related "bugs" otherwise. It's an odd mechanic, I'll say that though.

My guess is they instance is caught in an instance_change() loop because the stick is still held down. It's constantly "pressing" down every step until you let go.
 

Liam Earles

Member
I was going to say this doesn't work, but by jove you taught me something new! Not knowing about needing keyboard_key_release would have left me scratching my head over keyboard_key_press related "bugs" otherwise. It's an odd mechanic, I'll say that though.

My guess is they instance is caught in an instance_change() loop because the stick is still held down. It's constantly "pressing" down every step until you let go.
Okay so I got the analogue stick working, but the arrow keys and the D-pad don't work. When I try to hold down on either the arrow keys and the D-pad, it just goes right back to the idle object.

Here's the code for the step event in the 2nd object:
Code:
//Get the player's input
key_right = keyboard_check(vk_right) || (gamepad_axis_value(0,gp_axislh) > 0);
key_left = -(keyboard_check(vk_left) || (gamepad_axis_value(0,gp_axislh) < 0));
key_jump = keyboard_check_pressed(vk_space) || (gamepad_button_check_pressed(0,gp_face1));
key_down = keyboard_check(vk_down) || (gamepad_axis_value(0,gp_axislv) > 0);

//React to inputs
move = key_left + key_right;
hsp = move * movespeed;
if (vsp < 10) vsp += grav;

if (place_meeting(x,y+1,BrownBlock))

if gamepad_axis_value(0,gp_axislv) = 0
{
hspeed = 0
keyboard_check_released(vk_down)
instance_change(Ava, false)
}
else
{
hspeed = 7
keyboard_check_pressed(vk_down)
instance_change(AvaCartwheelTechnique, false)
}

{
    vsp = key_jump * -jumpspeed
}

//Horizontal Collision
if (place_meeting(x+hsp,y,BrownBlock))
{
    while(!place_meeting(x+sign(hsp),y,BrownBlock))
    {
        x += sign(hsp);
    }
    hsp = 0;
}
x += hsp;

//Vertical Collision
if (place_meeting(x,y+vsp,BrownBlock))
{
    while(!place_meeting(x,y+sign(vsp),BrownBlock))
    {
        y += sign(vsp);
    }
    vsp = 0;
}
y += vsp;
Here's the other piece of code from the same object's step event:
Code:
if gamepad_button_check_pressed(0,gp_padd)
{
keyboard_key_press(vk_down)
keyboard_key_release(vk_down)
}

if gamepad_button_check_pressed(0,gp_start)
{
keyboard_key_press(vk_enter)
keyboard_key_release(vk_enter)
}

if gamepad_button_check_pressed(0,gp_select)
{
keyboard_key_press(vk_shift)
keyboard_key_release(vk_shift)
}

if gamepad_button_check_released(0,gp_face1)
{
keyboard_key_release(ord('X'))
keyboard_key_release(vk_space)
}

if gamepad_button_check_released(0,gp_padu)
{
keyboard_key_release(vk_up)
}

if gamepad_button_check_pressed(0,gp_padu)
{
keyboard_key_press(vk_up)
}

if gamepad_button_check_pressed(0, gp_face3)
{
keyboard_key_press(ord("Z"))
instance_change(AvaSpinKick, false)
}

if gamepad_button_check_pressed(0, gp_face1)
{
keyboard_key_press(ord("X"))
}

if gamepad_axis_value(0,gp_axislv) < 0
{
keyboard_key_press(vk_up)
keyboard_key_release(vk_up)
}

if gamepad_axis_value(0,gp_axislh) > 0
{
keyboard_key_press(vk_right)
keyboard_key_release(vk_right)
}

if gamepad_axis_value(0,gp_axislh) < 0
{
keyboard_key_press(vk_left)
keyboard_key_release(vk_left)
}
Let me know ASAP for any fixes.
 

TheouAegis

Member
Are you remembering to put an "if" in front of keyboard_check calls? It doesn't look like it in the code snippet you showed.
 

Liam Earles

Member
Okay so when the analogue stick doesn't work correctly, the D-Pad and Arrow keys work, but if the stick does work, the D-Pad and the arrow keys don't work. So here's what i have for code.

Idle Step 1st Code piece:
Code:
//Get the player's input
key_right = keyboard_check(vk_right) || (gamepad_axis_value(0,gp_axislh) > 0);
key_left = -(keyboard_check(vk_left) || (gamepad_axis_value(0,gp_axislh) < 0));
key_jump = keyboard_check_pressed(vk_space) || (gamepad_button_check_pressed(0,gp_face1));
key_down = keyboard_check(vk_down) || (gamepad_axis_value(0,gp_axislv) > 0);
down_imp = (gamepad_axis_value(0,gp_axislv) = 0) || keyboard_key_press(vk_down);
down_release = (gamepad_axis_value(0,gp_axislv) = 0) || keyboard_key_press(vk_down)

//React to inputs
move = key_left + key_right;
hsp = move * movespeed;
if (vsp < 10) vsp += grav;

if (place_meeting(x,y+1,BrownBlock))

if gamepad_axis_value(0,gp_axislv) = 0
if key_down
if down_imp
if down_release
{
if keyboard_key_release(vk_down)
instance_change(Ava, false)
movespeed = 0
}
else
{
keyboard_key_press(vk_down)
instance_change(AvaCartwheelTechnique, false)
}
{
    vsp = key_jump * -jumpspeed
}
//Horizontal Collision
if (place_meeting(x+hsp,y,BrownBlock))
{
    while(!place_meeting(x+sign(hsp),y,BrownBlock))
    {
        x += sign(hsp);
    }
    hsp = 0;
}
x += hsp;

//Vertical Collision
if (place_meeting(x,y+vsp,BrownBlock))
{
    while(!place_meeting(x,y+sign(vsp),BrownBlock))
    {
        y += sign(vsp);
    }
    vsp = 0;
}
y += vsp;
Here's the second piece of code:
Code:
if gamepad_button_check_pressed(0,gp_start)
{
keyboard_key_press(vk_enter)
keyboard_key_release(vk_enter)
}

if gamepad_button_check_pressed(0,gp_select)
{
keyboard_key_press(vk_shift)
keyboard_key_release(vk_shift)
}


if gamepad_button_check_released(0,gp_padu)
{
keyboard_key_release(vk_up)
}

if gamepad_button_check_pressed(0,gp_padu)
{
keyboard_key_press(vk_up)
}

if gamepad_button_check_pressed(0, gp_face3)
{
keyboard_key_press(ord('Z'))
}

if gamepad_button_check_pressed(0,gp_padl)
{
keyboard_key_press(vk_left)
}


if gamepad_axis_value(0,gp_axislv) < 0
{
keyboard_key_press(vk_up)
keyboard_key_release(vk_up)
}

if gamepad_axis_value(0,gp_axislh) > 0
{
keyboard_key_press(vk_right)
keyboard_key_release(vk_right)
}

if gamepad_axis_value(0,gp_axislh) < 0
{
keyboard_key_press(vk_left)
keyboard_key_release(vk_left)
}
Here's the 1st piece of code for the cartwheel object:
Code:
if gamepad_button_check_pressed(0,gp_start)
{
keyboard_key_press(vk_enter)
keyboard_key_release(vk_enter)
}

if gamepad_button_check_pressed(0,gp_select)
{
keyboard_key_press(vk_shift)
keyboard_key_release(vk_shift)
}

if gamepad_button_check_released(0,gp_face1)
{
keyboard_key_release(ord('X'))
keyboard_key_release(vk_space)
}

if gamepad_button_check_released(0,gp_padu)
{
keyboard_key_release(vk_up)
}

if gamepad_button_check_pressed(0,gp_padu)
{
keyboard_key_press(vk_up)
}

if gamepad_button_check_pressed(0, gp_face3)
{
if keyboard_key_press(ord("Z"))
instance_change(AvaSpinKick, false)
}

if gamepad_button_check_pressed(0, gp_face1)
{
keyboard_key_press(ord("X"))
}

if gamepad_axis_value(0,gp_axislv) < 0
{
keyboard_key_press(vk_up)
keyboard_key_release(vk_up)
}

if gamepad_axis_value(0,gp_axislh) > 0
{
keyboard_key_press(vk_right)
keyboard_key_release(vk_right)
}

if gamepad_axis_value(0,gp_axislh) < 0
{
keyboard_key_press(vk_left)
keyboard_key_release(vk_left)
}
Here's the second piece of code:
Code:
//Get the player's input
key_right = keyboard_check(vk_right) || (gamepad_axis_value(0,gp_axislh) > 0);
key_left = -(keyboard_check(vk_left) || (gamepad_axis_value(0,gp_axislh) < 0));
key_jump = keyboard_check_pressed(vk_space) || (gamepad_button_check_pressed(0,gp_face1));
key_down = keyboard_check(vk_down) || (gamepad_axis_value(0,gp_axislv) > 0);
down_imp = (gamepad_axis_value(0,gp_axislv) > 0) || keyboard_key_release(vk_down);
down_release = (gamepad_axis_value(0,gp_axislv) = 0) || keyboard_key_press(vk_down)

//React to inputs
move = key_left + key_right;
hsp = move * movespeed;
if (vsp < 10) vsp += grav;

if (place_meeting(x,y+1,BrownBlock))

if down_imp
if key_down
if gamepad_axis_value(0,gp_axislv) = 0
{
if keyboard_key_release(vk_down)
if keyboard_check_released(vk_down)
instance_change(Ava, false)
movespeed = 0
}
else
{
keyboard_key_press(vk_down)
instance_change(AvaCartwheelTechnique, false)
}

{
    vsp = key_jump * -jumpspeed
}

//Horizontal Collision
if (place_meeting(x+hsp,y,BrownBlock))
{
    while(!place_meeting(x+sign(hsp),y,BrownBlock))
    {
        x += sign(hsp);
    }
    hsp = 0;
}
x += hsp;

//Vertical Collision
if (place_meeting(x,y+vsp,BrownBlock))
{
    while(!place_meeting(x,y+sign(vsp),BrownBlock))
    {
        y += sign(vsp);
    }
    vsp = 0;
}
y += vsp;
Let me know ASAP on how to fix this annoying bug.
 
Top