SOLVED Hi people. I am trying to code buttons for a title screen, but it shows an error for the UI manager when it compiles. Please help if you can?

S

SlFinn

Guest
The error is this: Variable obj_button._click(100041, -2147483648) not set before reading it. I have only been using GML and Game Maker for 5 days so I am not certain what this means or how to fix it. I will insert the code I have used below that is supposedly has this error. I am hoping someone can help me understand what needs fixing and how. I'd really appreciate it!

The code for my User Event 0 (which has the error):

GML:
var _width = 300;
var _height = 100;

create_button(40, 40, _width, _height, "Play", on_click);
create_button(40, 40 + _height + 40, _width, _height, "Options", on_click);
create_button(40, 40 + (_height + 40) * 2, _width, _height, "Quit", on_click);
Also in case you need to see my create and step events to give you more info on my UI manager, I will print them below:

Button Manager Create event:

menuOpen = false;
Code:
menuOpen = false;
Button Manager Step event:

Code:
if(keyboard-check_pressed(ord("M"))) {
    menuOpen = !menuOpen;
    if(menuOpen)
    event_user(0);
    else
    event_user(1);
}
Btw these are my create, step and draw gui events for my obj_button in case you need this information:

Create:

GML:
width = 280;
height = 80;

text = "Start Game";

hover = 0;

script = -1;
Step:

Code:
var _hover = get_hover();
var_click = _hover && mouse_check_button_pressed(mb_left);

hover = lerp(hover, _hover, 0.1);
y = lerp(y, ystart - _hover *8, 0.1);

if(_click && script >= 0) {
    script_execute(script);
}
Draw Gui:

Code:
draw_set_color(merge_color(c_ltgray, c_red, hover));

draw_roundrect(x, y, x + width, y + height, 0);

draw_set_color(c_red);
draw_set_halign(fa_center);
draw_set_valign(fa_middle);
draw_text(x + width/2, y + height/2, text);
draw_set_halign(fa_left);
draw_set_valign(fa_top);

draw_set_color(c_red);
 

TsukaYuriko

☄️
Forum Staff
Moderator
Is that all the code? I don't see any variable called _click, only on_click. Also, keyboard-check_pressed should probably keyboard_check_pressed.

Either way, the error is caused because you're trying to reference a variable (_click) that hasn't been initialized yet.


Edit: Wasn't all the code. :) Please post the full error message as well, so we know what is throwing the error.
 
S

SlFinn

Guest
Thank you :)

The full error was this....I'm not sure how to initialise the _click method though so that it works. I was following a YouTube tutorial you see. I did exactly what the guy on the
tutorial did and it worked for him. Thank you for telling me what the main problem was. I am not sure what to do to initialise the _click method correctly though.

ERROR in
action number 1
of Step Event0
for object obj_button:

Variable obj_button._click(100041, -2147483648) not set before reading it.
at gml_Object_obj_button_Step_0 (line 9) - if(_click && script >= 0) {
############################################################################################
gml_Object_obj_button_Step_0 (line 9)
 
Top