• 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] Problem with using a string

I am trying to make an editor of text files, and want to read through the contents of a string from the file being read.

The problem I've having is that I'm trying to accommodate for spaces in the read code, such as if someone has indented it per the generally accepted coding style.

Having tried various things I'm a bit stumped as to what "value" a non character position in the string returns. Undefined?
"" ?

Code:
begin_pos = 1;
result = "first char in str = " + string_char_at(text, 1);
ds_list_add(str_results, result);

if string_char_at(text, begin_pos) == ""
{
while (string_char_at(text, begin_pos) == "")
{
begin_pos += 1
}
result = "counted through spaces in line of text";
ds_list_add(str_results, result);
}
The above code doesn't work, even though it shows the first character as being nothing. It says it's nothing, though that should see another entry into a ds list that documents it. That doesn't happen.

If I look at the second character it shows the first letter of the text that I'd expect to see, so there is definitely space in the string at the beginning.

So what is wrong here? Thanks in advance for any help figuring this out. Cheers!
 

FrostyCat

Redemption Seeker
Do you know the difference between an empty string ("") and a string containing a single space character (" ")?

Also, depending on the settings of the text editor used to create the file, tabs may also be represented as chr(9) ("\t" in GMS 2). You should check for that too, just in case.
 
Do you know the difference between an empty string ("") and a string containing a single space character (" ")?

Also, depending on the settings of the text editor used to create the file, tabs may also be represented as chr(9). You should check for that too, just in case.
I've tried using " " (an empty space) and it still won't register it. But I can see it's there.

EDIT: Sorry! I just twigged the tabs bit. That's how I indented it in the file I'm reading, so it will (maybe) return chr(9). Thanks - I'll check for that.
 
Last edited:

FrostyCat

Redemption Seeker
Then get a hex editor and inspect what kind of whitespace character is there. It could be a tab character (which you would detect as chr(9) instead of " ") or something else on this table.
 
Top