• 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!

GML Implement 3 Letter Character Input Limit to Online High Score Table

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:


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
Alarm[0]

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
    }
}
 

FrostyCat

Redemption Seeker
Replace this:
GML:
max_width=200 //maximum width
With this:
GML:
max_chars = 3; //maximum characters
And this:
GML:
if (string_width(keyboard_string) < max_width) //if keyboard_string's width is smaller than the maximum
With this:
GML:
if (string_length(keyboard_string) < max_chars) //if keyboard_string's length is smaller than the maximum
 
Top