Gladius Opublikowano 25 Maja 2014 Opublikowano 25 Maja 2014 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 }
ereg Opublikowano 25 Maja 2014 Opublikowano 25 Maja 2014 kdzie masz definowane: length text akcja sie bedzie dziac(po wcisnieciu ENTER), ale z tego co pokazujesz skoczy sie bledem :)
Gladius Opublikowano 26 Maja 2014 Autor Opublikowano 26 Maja 2014 Ereg ty o coś pytasz czy tłumaczysz? :D Bo nie do końca rozumiem twoją wypowiedź :D
ereg Opublikowano 26 Maja 2014 Opublikowano 26 Maja 2014 przepraszam :) 1, kdzie masz definowane ? - length - text 2a, stwierdzam: akcja sie bedzie dziac(po wcisnieciu ENTER) 2b, tlumacze dlaczego pytam v punktu 1, : ale z tego co pokazujesz skoczy sie bledem 3a, chyba JA zle przeczytalem twe pytanie. jesli chodzilo ci by akcja byla wykonana po napisaniu unikalnego slowa to mozesz porownywac stringi. GML if (_string_zadany_w_input == _string_szukany) && (keyboard_check_pressed(vk_enter)) ) { /* wykonaj akcje*/ }; 3b, ten sam sposob jako v 3a, ale inne wykonanie. szuka dokladnie ten sam string. naprz jesli "hello world" jest w "hello" wynik bedzie false GML if (string_pos(_string_zadany_w_input, _string_szukany) && (keyboard_check_pressed(vk_enter)) ) { /* wykonaj akcje*/ }; // string_pos wraca 0/false kdy nic nieznalazl</span> 3c, tak jak v 3b, ale tym razem szuka jesli string jest wogole w zadanym stringu. naprz jesli "hello" jest w "hello world" wynik bedzie true GML if (string_pos( _string_szukany, _string_zadany_w_input) && (keyboard_check_pressed(vk_enter)) ) { /* wykonaj akcje*/ }; // string_pos wraca 0/false kdy nic nieznalazl</span>
Gladius Opublikowano 27 Maja 2014 Autor Opublikowano 27 Maja 2014 Takich kombinacji sam próbowałem, ale nie mam pojęcia co wpisać jako "string_zadany_w_input" :/
ereg Opublikowano 27 Maja 2014 Opublikowano 27 Maja 2014 "_string_zadany_w_input" jest twa zmienna, ktora przechowuje string tobo napisany string do boxu naprzyklad: GML _string_szukany="hello"; _string_zadany_w_input=get_string("napisz hello","tu"); // tu dasz swoj sposob pozyskania napisanego stringu if (_string_zadany_w_input == _string_szukany) && (keyboard_check_pressed(vk_enter)) ) { /* wykonaj akcje*/ show_message( 'napisalesz "hello" ' ); };
Gladius Opublikowano 28 Maja 2014 Autor Opublikowano 28 Maja 2014 Ale właśnie o to chodzi, że niewiem jak pozyskać string wpisany w tym boksie. O to pytam od początku :D
Administratorzy gnysek Opublikowano 28 Maja 2014 Administratorzy Opublikowano 28 Maja 2014 Jeśli chodzi o skrypt na górze, to zamiast _string_zadany_w_input wpisz text.
Rekomendowane odpowiedzi
Jeśli chcesz dodać odpowiedź, zaloguj się lub zarejestruj nowe konto
Jedynie zarejestrowani użytkownicy mogą komentować zawartość tej strony.
Zarejestruj nowe konto
Załóż nowe konto. To bardzo proste!
Zarejestruj sięZaloguj się
Posiadasz już konto? Zaloguj się poniżej.
Zaloguj się