RATED ARCADE
Member
I'm in need of assistance with my current code. I'm looking to set up a 3 letter (only) character limit to the name input section of the online high score table.
My code thus far is as follows:
obj_input
Create Event:
Alarm[0]
Left Pressed Event:
Draw Event:
Press <Any Key> Event:
My code thus far is as follows:
obj_input
Create Event:
GML:
max_width=200 //maximum width
selected=true //is the player typing here?
blink=false //show "|"?
txt="" //what does it contain?
alarm[0]=30 //start the blinking animation
GML:
blink = !blink;
alarm[0]=30; //reset the alarm
Left Pressed Event:
GML:
selected = true; //player is typing in this box
keyboard_string = txt;
Draw Event:
GML:
draw_set_font(font_Scoreboard_2);
draw_self();
draw_set_halign(fa_middle); //draw it in the middle of the sprite
draw_set_valign(fa_center);
draw_set_color(make_colour_rgb(183, 224, 31));
if (txt == "")
{
draw_text(x,y,"Name");
}
else
{
if (blink == false) || (selected == false)
{
draw_text(x,y,txt); //draw the text
}
else
{
draw_text(x,y,txt + "|"); //draw the text with a "|" in the end
}
}
Press <Any Key> Event:
GML:
if (selected == true)
{
if (string_width(keyboard_string) < max_width) //if keyboard_string's width is smaller than the maximum
{
txt = keyboard_string; //set txt to keyboard_string
}
else
{
keyboard_string = txt; //set keyboard_string to txt
}
}