keyboard_check_pressed using any key argument?

I've been trying to code a scrolling interactive menu and been running into some trouble. I use what I think is a pretty simple argument to check if the mouse is touching a selection box when pressed - if its x is between the bounds of the box, and its y is between the bounds of the box cut into the number of entries on the screen (in this case, 10 rectangles each with textboxheight/10 as height). This changes the selected entry's font from the regular color to a bright yellow color. However, I've been running into some odd issues with the left mouse button press.

Pressing the left mouse button directly on the desired entry does nothing. To troubleshoot this, I simplified the problem by making the first entry always selected if the mouse button is pressed within the x boundaries of the textbox. However, this still does nothing... until another key is pressed (doesn't matter what). The moment any other key is pressed, the first entry will light up yellow exactly as planned - but it still completely ignores the mouse.

I've attached what I believe is all the relevant code for the object (there are other events for moving the view around and scrolling the textbox, but those don't seem to affect anything). Views are turned on and the object is always offset from the room's view by a fixed amount. Can anyone spot why this is happening?


Create:
GML:
///dropdown selection bar
f=1;//current topmost position, set at 0 to start with
global.selected=0;
global.basicfont=font_add_sprite_ext(spr_font,"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz?!,.-'♂♀01234",true,1);
global.selectedfont=font_add_sprite_ext(spr_font_selected,"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz?!,.-'♂♀01234",true,1);
Step:
GML:
x=view_xview+200;
y=view_yview+15;
global.trackx=x;
global.tracky=y;
global.trackmx=mouse_x;
global.trackmy=mouse_y;

if keyboard_check_pressed(mb_left){
if ((x<mouse_x) and (mouse_x<(x+100))){
global.selected=f;
}
}
Draw:
GML:
draw_rectangle_color(x-2,y-2,x+100,y+115,c_white,c_white,c_white,c_white,false);
draw_rectangle_color(x-2,y-2,x+100,y+115,c_black,c_black,c_black,c_black,true);

draw_rectangle_color(x-2,y-2,x+100,y+10,c_white,c_white,c_white,c_white,false);
draw_rectangle_color(x-2,y-2,x+100,y+10,c_black,c_black,c_black,c_black,true);

for(i=0;i<10;i++){
if (f+i)<494{
if (f+i)!=global.selected{
draw_set_font(global.basicfont);
}
else if (f+i)==global.selected{
draw_set_font(global.selectedfont);
}
draw_text(x,y+12+(10*i),L[f+i]);
}
}
 
That worked perfectly, thanks!

Incidentally, is that a recent thing? I haven't touched GMS in about 2 years, but I feel like I've used mouse buttons in keyboard arguments before.
 

ophelius

Member
Incidentally, is that a recent thing? I haven't touched GMS in about 2 years, but I feel like I've used mouse buttons in keyboard arguments before.
Never heard of that before, to my knowledge keyboards and mice always had separate functions to check input
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
Although both mb_ and vk_ constants map to integers, mb_any has a different value from vk_any. You can experiment with displaying their values.
 
Top