• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Text not showing up

Y

Yvalson

Guest
So I'm currently setting up a system that should let players use a controller in my game.
however some text isn't showing up

I'm using this code inside a mouse left pressed event:

Code:
if(!searching && global.gamepad = -1){
    searching = 1
}

else if(!searching && !global.gamepad = -1){
    global.gamepad = -1
}

else if(searching && global.gamepad = -1){
    searching = 0
}
it should check in which state the gamepad detection button currently is.

(searching is set to 0 in the create event and global.gamepad is set to -1)

so when a player presses the button and nothing has happened yet it should start searching because searching will be set to 1.

this will start the searching code in the step event:

Code:
if(searching){
    var gp_num = gamepad_get_device_count();
    for (var i = 0; i < gp_num; i++;){
        if gamepad_button_check(i, gp_start){
            global.gamepad = i
            searching = 0
            show_message(string(searching) + string(global.gamepad))
            break;
        }
    }
}

if(global.gamepad = -1){
    sprite_index = Spr_Unselected
}

else if(global.gamepad != -1){
    sprite_index = Spr_Selected
}
so when a player presses the home/start button of their controller the code should detect in which slot it is and then assign the slot number to global.gamepad.

following in which state the code is in this text should show up (Draw GUI event):

Code:
draw_set_font(f_Store)
if(!searching && global.gamepad = -1){
   draw_text(32, 520, "No gamepad connected")
   draw_text(32, 580, "Disable this option before disconnecting.")
}

else if(searching && global.gamepad = -1){
    draw_text(32, 520, "Looking for gamepad...")
    draw_text(32, 580, "Press the Start/Option button.")
    draw_text(32, 640, "Press the search button to stop.")
}

else if(!searching && !global.gamepad = -1){
    draw_text(32, 520, "Gamepad connected!")
    draw_text(32, 580, "Disable this option before disconnecting.")
}
No gamepad connected and looking for gamepad... both show up. however the Gamepad connected text doesn't however using the show_message I can see that searching is set to 0 again and that global.gamepad != -1 however I'm not able to see the text or disconnect the controller by clicking on the detection button again. instead it will keep being in the connected state.

can someone tell me what's wrong?
 

Ubu

Member
If you don't absolutely need to check for a home/start button press, you should replace the following 2 lines:
Code:
if gamepad_button_check(i, gp_start){
    global.gamepad = i
with:
Code:
if gamepad_is_connected(i){
    global.gamepad[i] = true;
and the gamepad will automatically show up.

If you want to check for a home/start button press you'll have to add a check for gamepad_button_check_pressed in addition to the gamepad_is_connected check.
 
Y

Yvalson

Guest
If you don't absolutely need to check for a home/start button press, you should replace the following 2 lines:
Code:
if gamepad_button_check(i, gp_start){
    global.gamepad = i
with:
Code:
if gamepad_is_connected(i){
    global.gamepad[i] = true;
and the gamepad will automatically show up.

If you want to check for a home/start button press you'll have to add a check for gamepad_button_check_pressed in addition to the gamepad_is_connected check.
Yeah I have to check for it with a button press because Gamemaker detects all Bluetooth devices as gamepads so I have to press a button so I can loop through the slots and see in what slot the button was pressed.
Also the gamepad is not the problem it gets detected perfectly the problem is that the text isn't showing and that the button gets stuck in the selected state
 

Ubu

Member
I believe you still have to check if the gamepad is connected before checking for a button press.
So change your code to:
Code:
if(searching){
    var gp_num = gamepad_get_device_count();
    for (var i = 0; i < gp_num; i++;){
        if gamepad_is_connected(i){
            if gamepad_button_check_pressed(i, gp_start)
            {
                global.gamepad[i] = true
                searching = 0
                show_message(string(searching) + string(global.gamepad))
                break;
            }
        }
    }
}
I also found an error in you draw gui event:
This:
Code:
else if(!searching && !global.gamepad = -1){
should read:
Code:
else if(!searching && global.gamepad != -1){
 
Y

Yvalson

Guest
I believe you still have to check if the gamepad is connected before checking for a button press.
So change your code to:
Code:
if(searching){
    var gp_num = gamepad_get_device_count();
    for (var i = 0; i < gp_num; i++;){
        if gamepad_is_connected(i){
            if gamepad_button_check_pressed(i, gp_start)
            {
                global.gamepad[i] = true
                searching = 0
                show_message(string(searching) + string(global.gamepad))
                break;
            }
        }
    }
}
I also found an error in you draw gui event:
This:
Code:
else if(!searching && !global.gamepad = -1){
should read:
Code:
else if(!searching && global.gamepad != -1){
Alright will do, I'll also change the other thing as I think that's the culprit of my problem
 
Top