R
Rosieu
Guest
Hi again everyone, It's been a while!
I've had a tiny bit of spare time recently, and I thought I'd get back into some gamedev stuff. I've only been back into it a couple of days though, and I've hit something of a road block!
Basically, I've been trying to figure out a way to make an engine where the player/user can type a word, and then the game checks it off against some data (in my case a ds_list of 'words') and returns true/1 if the word the player typed is found, and false/0 if not. The trouble is, I can't actually get the check to work!
I'll include my code (which was adapted from various sources which I then build upon) below, in case it's just some stupid mistake I've been blind to!
While I've commented one of them out, I have tried two ways of running a check for the typed word, both one using a simple ds_list_find_index() and the other using a 'for' loop and assessors. When I change the value it checks for to a string in the code, it works fine, however if I try and get it to check for the variable "currentword" it just doesn't work. Does anyone have any ideas where I'm going wrong?
On a slightly different tact, I thought I would try rejigging the 'currentword' variable to be a ds_stack of the letters typed, because it's LIFO nature made the ability to delete letters very simple. Problem is, I have no clue how to go about converting the entire stack to string to be stored in a variable. Does anyone have an idea about how I could do this?
Sorry about the random questions, and thanks for your patience!
Edit: I think I found my problem! I think the pressing of a key to cue the check was actually adding that key's contents to the variable to test. So I would type in "test" then hit enter to see if "test" was in the word bank, however the check would be looking for "test" as well as the enter key. I converted the string to check into letters with string_letters() and it seemed to do the trick!
I've had a tiny bit of spare time recently, and I thought I'd get back into some gamedev stuff. I've only been back into it a couple of days though, and I've hit something of a road block!
Basically, I've been trying to figure out a way to make an engine where the player/user can type a word, and then the game checks it off against some data (in my case a ds_list of 'words') and returns true/1 if the word the player typed is found, and false/0 if not. The trouble is, I can't actually get the check to work!
I'll include my code (which was adapted from various sources which I then build upon) below, in case it's just some stupid mistake I've been blind to!
Code:
if writing == 0
{
if keyboard_lastkey != -1
{
if keyboard_lastchar != vk_enter && keyboard_lastchar != vk_space
{
currentword += keyboard_lastchar; //Add the last key
keyboard_lastkey = -1;
}
}
if keyboard_check_pressed(vk_enter) && currentword != ""
{
writing = 1
//wordcheck = ds_list_find_index(global.wordlist,currentword)
var wpos;
for (wpos = 0; wpos < (ds_list_size(global.wordlist)-1); wpos += 1)
{
if global.wordlist[| wpos] == string(currentword)
{
wordcheck = 1;
}
else
{
wordcheck = 0;
}
}
}
}
if writing == 1
{
//check to see if the word entered exists in list of words
if wordcheck != 0
{
wordfound = true;
//continues the game
currentword = "";
writing = 2;
}
else
{
wordfound = false
writing = 2;
currentword = "";
}
}
While I've commented one of them out, I have tried two ways of running a check for the typed word, both one using a simple ds_list_find_index() and the other using a 'for' loop and assessors. When I change the value it checks for to a string in the code, it works fine, however if I try and get it to check for the variable "currentword" it just doesn't work. Does anyone have any ideas where I'm going wrong?
On a slightly different tact, I thought I would try rejigging the 'currentword' variable to be a ds_stack of the letters typed, because it's LIFO nature made the ability to delete letters very simple. Problem is, I have no clue how to go about converting the entire stack to string to be stored in a variable. Does anyone have an idea about how I could do this?
Sorry about the random questions, and thanks for your patience!
Edit: I think I found my problem! I think the pressing of a key to cue the check was actually adding that key's contents to the variable to test. So I would type in "test" then hit enter to see if "test" was in the word bank, however the check would be looking for "test" as well as the enter key. I converted the string to check into letters with string_letters() and it seemed to do the trick!
Last edited by a moderator: