Jako że jestem noobem, przykład pola tekstowego wziąłem sobie z internetu.
A więc mam dwa obiekty: obj_input i obj_log.
Log jest tylko cieniem wpisanego tekstu, więc chyba nie będzie tu potrzebny.
Problem polega na tym, iż nie wiem jak sprawić by po wpisanu tylko jakiegoś odpowiedniego wyrażenia, np. "Hello" działa się jakaś akcja.
Create z obj_input:
GML (create)
caret_flash = 0
caret_flash_rate = 15
caret_move = 0
caret_move_rate = 7
text = "" // current text
caret = 0 // caret position
fillchar = "`" // used as filler character in input handling.
filltext = string_repeat(fillchar, 10)
Step z obj_input:
GML (step)
// keyboard shortcuts:
caret_move = max(0, caret_move - 1)
if (keyboard_check(vk_left) != keyboard_check(vk_right)) {
if (caret_move == 0) {
if (keyboard_check(vk_left)) {
if (caret > 0) caret -= 1
} else {
if (caret < string_length(text)) caret += 1
}
caret_move = caret_move_rate
}
} else caret_move = 0
if (keyboard_check_pressed(vk_home)) caret = 0
if (keyboard_check_pressed(vk_end)) caret = string_length(text)
if (keyboard_check_pressed(vk_delete)) {
text = string_delete(text, caret + 1, 1)
}
// actual input:
if (keyboard_string != filltext && keyboard_string != "") {
var n, l, t;
t = keyboard_string
l = string_length(t)
n = 1
// find where actual input starts
while ((n <= l) && (string_char_at(t, n) == fillchar)) n += 1
c = 11 - n
if (c > 0 && caret > 0) {
caret -= c
text = string_delete(text, caret + 1, c)
}
c = l - n + 1
if (c > 0) {
text = string_insert(string_copy(t, n, c), text, caret + 1)
caret += c
}
}
keyboard_string = filltext
caret = max(0, min(caret, string_length(text)))
Draw z obj_input:
GML (draw)
draw_set_font(LCD)
draw_set_color(make_color_rgb(0, 245, 57))
var i, h, ptext;
// sad truth: There is no way you can display the typed "#"
// characters and get string width of those.
ptext = string_replace_all(text, '#', '¹')
draw_text(x, y, ptext)
// add those useless fancy lines below the input:
i = string_width(string_copy(ptext, 1, caret))
h = string_height('\\')
draw_line(x + i, y, x + i, y + h)
i = string_width(text)
draw_line(x - 3, y + h + 2, x + i + 2, y + h + 2)
draw_line(x - 3, y + h + 4, x + i + 10, y + h + 4)
// key handling:
if (keyboard_check_pressed(vk_enter)) {
with (obj_log) {
for (i = length - 1; i >= 0; i -= 1) text[i + 1] = text
length = min(maxlength, length + 1)
text[0] = ptext
}
text = ''
caret = 0
}