Phoebe Klim
Member
I'm trying to improve spaceship renaming for my game,
I'm using this code to rename in the Press <any key> event:
The problem is that strange things happen when I press Tab, Caps Lock, Ctrl, etc.
How can I prevent non-symbol keys from ruining the name?
I used to have a script that would only allow adding letters to the name, but I don't want to use it anymore, because of localization reasons.
I could also make add a lot if keyboard_lastkey != <key> lines, but some keys don't seem to have built-in variables for them and there are different keyboards.
I'm using this code to rename in the Press <any key> event:
Code:
if mode_rename == true
{
if keyboard_lastkey != vk_backspace
{
if keyboard_lastkey != vk_enter
{
if keyboard_lastkey != vk_shift
{
if string_length(ship_name) < 22
{
if keyboard_lastchar != -1
{
if keyboard_check(vk_shift)
{
ship_name += string_upper(keyboard_lastchar);
}
else
{
ship_name += string_lower(keyboard_lastchar);
}
keyboard_lastchar = -1;
audio_play_sound(snd_button, 1, false);
}
}
else
{
scr_new_message(_t("error"), _t("name_error"), c_red);
keyboard_lastchar = -1;
audio_play_sound(snd_error_1, 1, false);
}
}
else
{
keyboard_lastchar = -1;
}
}
else
{
if ship_name != "" && ship_name != " "
{
mode_rename = false;
scr_achievement_check(18);
keyboard_lastchar = -1;
audio_play_sound(snd_button,1,false);
}
else
{
mode_rename = false;
ship_name = old_ship_name;
keyboard_lastchar = -1;
audio_play_sound(snd_button,1,false);
}
}
}
else
{
var edit = string_delete(ship_name, string_length(ship_name), 0);
ship_name = edit;
keyboard_lastchar = -1;
audio_play_sound(snd_button, 1, false);
}
}
The problem is that strange things happen when I press Tab, Caps Lock, Ctrl, etc.
How can I prevent non-symbol keys from ruining the name?
I used to have a script that would only allow adding letters to the name, but I don't want to use it anymore, because of localization reasons.
I could also make add a lot if keyboard_lastkey != <key> lines, but some keys don't seem to have built-in variables for them and there are different keyboards.