So I think i have it but just need some help.

I

Ieyfo

Guest
Hello again, in a past post I asked about taking a word and breaking it down the giving a chest one of the characters from the word and the character not being able to be used again. Well they tried to help and we ended up with a broken game so I've worked on it and followed the info they gave me but its not working.

So to start the word to be used is selected from an array of words randomly.

Code:
// Select word for map
scr_Word_Array()
var rand = irandom(87);
global.word = global.arrayWords[rand];

Next I take the word selected and break it down to a single letter and store it into an array.

Code:
// Break the word into a single char.
global.wordChar[0] = string_char_at(global.word, 1);
global.wordChar[1] = string_char_at(global.word, 1);
global.wordChar[2] = string_char_at(global.word, 1);
global.wordChar[3] = string_char_at(global.word, 1);
global.wordChar[4] = string_char_at(global.word, 1);
Then from there I put it into a ds_list (Yes I do create the ds_list at the top of the script)
Also I shuffle so i can make the letter placement random.

Code:
// Store all the chars into the list.
ds_list_add(charList, global.wordChar[0], global.wordChar[2], global.wordChar[3], global.wordChar[4]);
ds_list_shuffle(charList);
Now this is the part that i'm having an issue with.
Upon the creation of the chest I want to give it one of the letters.
The way i'm doing it is Using the ds_list selecting the first one setting the variable of letterStored to equal it then deleting it from the list. but that don't work.

What its doing is using the first letter of the word.
There was someone who was gonna help but he wanted remote access to my computer and hes probably a nice person and just wants to help but there is the chance he has other plans than help.

Code:
if(point_distance(ex, ey, obj_Player.x, obj_Player.y) > 250 && instance_number(obj_Chest_Letter) <= 4 && irandom(lcodds) == lcodds){
                with instance_create(lcx, lcy, obj_Chest_Letter)
                letterStored = ds_list_find_value(other.charList, 0);
                ds_list_delete(charList, 0);
}
So why isn't this working the way it should?
 
Q

Quackertree

Guest
Code:
// Break the word into a single char.
global.wordChar[0] = string_char_at(global.word, 1);
global.wordChar[1] = string_char_at(global.word, 1);
global.wordChar[2] = string_char_at(global.word, 1);
global.wordChar[3] = string_char_at(global.word, 1);
global.wordChar[4] = string_char_at(global.word, 1);
That wouldn't work at all. Now you're just grabbing the first character from the string. Everytime.

The char_at should be 1, 2, 3, etc. not 1, 1, 1.

Alternatively, give it an iterate:

Code:
for(i=0;i<string_length(global.word);i++)
{
global.wordChar[i] = string_char_at(global.word, i + 1);
}
EDIT: Now actually read the problem; If you run that last bit of code in your step event, it'll constantly delete indexes and eventually the list will run empty (within 1/10 of a second, probably), which probably results in an empty string. You should only grab the value once, or, not delete the index.
 
I

Ieyfo

Guest
Code:
// Break the word into a single char.
global.wordChar[0] = string_char_at(global.word, 1);
global.wordChar[1] = string_char_at(global.word, 1);
global.wordChar[2] = string_char_at(global.word, 1);
global.wordChar[3] = string_char_at(global.word, 1);
global.wordChar[4] = string_char_at(global.word, 1);
That wouldn't work at all. Now you're just grabbing the first character from the string. Everytime.

The char_at should be 1, 2, 3, etc. not 1, 1, 1.

Alternatively, give it an iterate:

Code:
for(i=0;i<string_length(global.word);i++)
{
global.wordChar[i] = string_char_at(global.word, i + 1);
}
EDIT: Now actually read the problem; If you run that last bit of code in your step event, it'll constantly delete indexes and eventually the list will run empty (within 1/10 of a second, probably), which probably results in an empty string. You should only grab the value once, or, not delete the index.

Yea so i fixed the string_char_at issue but for some reason the second letter is lost and undefined.

EDIT: This is all done in the create event. Its al part of the level generation.
 
Q

Quackertree

Guest
Probably because of this:

Code:
// Store all the chars into the list.
ds_list_add(charList, global.wordChar[0], global.wordChar[2], global.wordChar[3], global.wordChar[4]);
ds_list_shuffle(charList);
You forgot to add global.wordChar[1]...

Once again, an iteration would've helped you out here. :)
 
I

Ieyfo

Guest
Probably because of this:

Code:
// Store all the chars into the list.
ds_list_add(charList, global.wordChar[0], global.wordChar[2], global.wordChar[3], global.wordChar[4]);
ds_list_shuffle(charList);
You forgot to add global.wordChar[1]...

Once again, an iteration would've helped you out here. :)
Many thanks lmao. Sometimes you have to have someone else look at it thanks.
 
Top