W
WilliamShakesbeer
Guest
I made (borrowed) a script for drawing buttons to gui and it works perfectly, except I cannot seem to assign a variable to the returned value.
Here is the script:
So then I put this code in the draw gui for the button object:
I know that the button itself works because I can get the debug message showing that r is equal to 2. However, I can't get var a to equal 2. It's clearly not getting the return r. This is my first attempt at a function since my GM2 was just updated. Can anyone tell me what I'm doing wrong? TIA
Here is the script:
Code:
/// @function draw_gui_button_sprite(sprite, index, x, y, width, height, main_view);
/// @param {index} sprite The sprite to draw
/// @param {index} index The sprites index
/// @param {real} x The x location of the sprite
/// @param {real} y The y location of the sprite
/// @param {real} width The width of the sprite
/// @param {real} height The height of the sprite
/// @param {index} main_view The camera view for the sprite
function draw_gui_button_sprite(sp, in, xx, yy, ww, hh, main_view){
var vi = 0;
if argument_count > 6 vi = argument[6];
main_view = vi;
var mx = mouse_x;
var my = mouse_y;
mx -= camera_get_view_x(view_camera[0]);
my -= camera_get_view_y(view_camera[0]);
mx *= (display_get_gui_width()) / (camera_get_view_width(view_camera[0]));
my *= (display_get_gui_height()) / (camera_get_view_height(view_camera[0]));
var on = mx > xx && mx < xx+ww && my > yy && my < yy+hh;
draw_sprite_ext(sp, in, xx, yy, ww/sprite_get_width(sp),
hh/sprite_get_height(sp), 0, c_white, 1);
var r = 0 && show_debug_message("000000");
if on r = 1 && show_debug_message("111111");
if on && mouse_check_button_pressed(mb_left) r = 2 && show_debug_message("222222");
if on && mouse_check_button(mb_left) r = 3 && show_debug_message("333333");
if on && mouse_check_button_released(mb_left) r = 4 && show_debug_message("44444");
return r;
}
GML:
var a = draw_gui_button_sprite(spr_brite_button, 0, 250, 760, 64, 64, 0);
if a == 2 {
instance_create_layer(mouse_x, mouse_y, "Instances", obj_brite_3bbl);
show_debug_message("button was clicked");
a = 0;
}
I know that the button itself works because I can get the debug message showing that r is equal to 2. However, I can't get var a to equal 2. It's clearly not getting the return r. This is my first attempt at a function since my GM2 was just updated. Can anyone tell me what I'm doing wrong? TIA