I learned something new about GM today

Posted by Alert Games on Nov. 12, 2009, 10:37 p.m.

SO if you ever need to take individual characters from a line in a file using text_read, beware! There are random "0" characters(as in, the character value of 0).

for example, if you load the settings for a game using a single line:

line = file_text_read_string(file);

for (z=0; z<=string_length(line); z+=1) {

array_character[z] = string_char_at(line,z+1);

}

Keep in mind this is using a file generated from GM's file_text_write_string , so that may be a possible cause. Also, it is using string_char_at, however string_copy does return a 0 value also.

It is easy to combat though. Just check with this:

if (ord(string_char_at(line,z+1)) != 0) {

//set in array

}

but it will save that in the array which may mess up your values. so the easiest way is to do this. heres the whole code:

L=0;

for (z=0; z<=string_length(line); z+=1) {

if (ord(string_char_at(line,z+1)) != 0) {

array_character[L] = string_char_at(line,z+1);

L+=1;

}

}

I know most peeps would not need to adress this problem or even use GM anymore, but i posted it for shits.

…and it was pissing me off cause i didnt know what was wrong! lol >:(

Comments

SteveKB 14 years, 4 months ago

can you give us an example cuz I don't know wtf you're talkin'bout.

KaBob799 14 years, 4 months ago

o.o I've never heard of that problem

RC 14 years, 4 months ago

This is weirder than that time I had diarrhea and shat myself while I was sleeping.

Ferret 14 years, 4 months ago

Omg this is really useful for me thanks! :D

Cesque 14 years, 4 months ago

Never used text_read, so I mostly don't know what you're talking about. I am well aware, however, that GM gives you a lot of zeroes when it tries to interpret number variables as strings.

Quote:
This is weirder than that time I had diarrhea and shat myself while I was sleeping.

The use of "shat" automatically makes you awesome ^_^

Misconstruct 14 years, 4 months ago

Something sounds strange. It's been a while since I've done anything with files in GM, but I don't remember encountering such a problem.

Maybe the issue is with the code you're using to create the file?

OBELISK 14 years, 4 months ago

Quote:
This is weirder than that time I had diarrhea and shat myself while I was sleeping.

Alert Games 14 years, 4 months ago

8-3

leemcd56 14 years, 4 months ago

"Propane and propane accessories."