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

Legacy GM [SOLVED]stuff must happen if writing a word from a list into textbox

U

Uberpink

Guest
i have a text box where i can write stuff . need to have a huge list of words and if you write one of them into the textbox then some stuff happen

my code is as follows:
(create event)
text = ""

(some of the step event)
if (keyboard_check_pressed(vk_enter))
{
if text="aword" then....... //when i write "aword" then something could happen
}

(draw event)
draw_text(x,y,text);

so question is, would it be simple to make a list with words that are acceptable to write in the textbox and
once written , that word cant be used again (untill u restart game) ? never worked with tekst like that before so some tip from the pros would be nice :)
 
Last edited by a moderator:

PNelly

Member
You could store your trigger words in a ds_list and check for their presence inside your vk_enter block.
Code:
// create
trigger_words = ds_list_create();
// use ds_list_add(trigger_words, "word") to put your trigger words in the list
then to check
Code:
if(keyboard_check_pressed(vk_enter)){
     // see if word is present in the list
     var _index = ds_list_find_index(trigger_words, text);
     if(_index >= 0){ // index >= 0 means item is present in the list
          // do stuff ...
          // remove that word from the list to prevent reuse
          ds_list_delete(trigger_words, _index);
     }
}
 
U

Uberpink

Guest
That invicible list with words that are accepted written in the tekstbox, should or could it be an external list/file?
-where words are just put under each other like this? (will be couple of hundred words)

car
umbrella
boat
light
etc
etc
 

Tsa05

Member
Of course, but in GameMaker, they'll have to exist somehow--a ds_list is a good idea.
So you could do this:
Code:
word_list = ds_list_create();
var file = file_text_open_read("fileWithWords.txt");
while(!file_text_eof(file)){
    var word = file_text_read_string(file);
    ds_list_add(word_list, word);
    file_text_readln(file);
}
If you include "fileWithWords.txt" in your game, then the code above will result in a list containing each word from the file. Once it's in a ds_list, you can easily add words, remove words, find a word at random, search for a word, and so on.
 
U

Uberpink

Guest
Of course, but in GameMaker, they'll have to exist somehow--a ds_list is a good idea.
So you could do this:
Code:
word_list = ds_list_create();
var file = file_text_open_read("fileWithWords.txt");
while(!file_text_eof(file)){
    var word = file_text_read_string(file);
    ds_list_add(word_list, word);
    file_text_readln(file);
}
If you include "fileWithWords.txt" in your game, then the code above will result in a list containing each word from the file. Once it's in a ds_list, you can easily add words, remove words, find a word at random, search for a word, and so on.

i did load fileWithWords.txt into "included files" but got the errormessage: (your code going into the create event, right?)

for object obj_text_box:

File is not opened for reading.
at gml_Object_obj_text_box_CreateEvent_1 (line 9) - while(!file_text_eof(file)){
 
Last edited by a moderator:
U

Uberpink

Guest
ok i put the tekstfile in the directory "datafiles" in my project folder then it worked:)
 
U

Uberpink

Guest
This works very nice::) Now, I tried to copy some code i got in an earlier game into this... its some code that use sprite-numbers(spritefont), and it counts (increasing score) while you play

however it counts, but now i suddenly cant write in the tekstboks nor see the small white letters anymore, is it possible to have both? the normal small white font for writing in the tekstboks and a spritefont that counts how far uve gotten? wonder if there is some draw-crash somewhere.. using draw for both, or maybe i have to specify each font so it doesent get confused with each other or something....

code for the new graphic-font :

create event:
globalvar FONT;
FONT = font_add_sprite(gamefonts, ord("0"), 0, -7);
draw_set_color(c_white) //not sure if i need this since its sprites
draw_set_font(FONT);

then i draw the value of the score in an points-object,,, score is increased the longer u stay alive, but as described, i suddenly cant write in the little tekstboks anymore:)

im not good with fonts but suspect it could work if i in some way managed to isolate the new font code above to not be somewhat global (so it doesent interfere with the other small white tekst-boks font) hm
 
Last edited by a moderator:
U

Uberpink

Guest
i have no draw_set_font() for the small tekstboks font i made in the beginning, maybe thats the problem, as i can still write in the tekstboks, i just cant see the font:)
 
i would put the words into a map

the key would be the "command"

and then the value can hold whatever actions should be taken, and what arguments need to be given with that particular command.
 
U

Uberpink

Guest
Thanks for replies, will try, also worked with draw_set_font(FONT) for the graphic/sprite font:)
 
Top