Any way to GetLetter?
by Laralyn McWilliams · in Torque Game Builder · 05/01/2010 (1:02 pm) · 5 replies
I'm making a kind of maze game, and I'd like to store my level layouts in a really readable format like this:
I understand how to use getWord to read in a text file, but I don't see any way to read a single letter/character unless you use a delimiter (for getField or getRecord).
Is there a way to "getLetter" for fileIO?
Thanks!
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XX XXX XX XXX XXXXXXXXXXXXXXXXXXX XXX XX XXX XXXXXXXXXXXXXXXXXXX X X XXX XXXXXXXXXXXXXXXXXXX X X XXX XXX X X XXX XXX XXXXXXXXXXXXXXXXXXXXXX XXX XXX XXXXXXXXXXXXXXXXXXXXXX XXX XXX XX XXX XXX XXXXXXXXXXXX XXXXXXXXX XXX XXX XXX X XXX X XXX X X XXX XXXXX XXXXXXXXX X X XXX XXXXX XXXXXXXXX XXX XXXXXX XXX XXXXX XXX X XXX XXX XXX X XXXXX XXXX XXX XXXXX XXX X X X X X XXX X X X X XXX X XXX X XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
I understand how to use getWord to read in a text file, but I don't see any way to read a single letter/character unless you use a delimiter (for getField or getRecord).
Is there a way to "getLetter" for fileIO?
Thanks!
#2
05/01/2010 (1:17 pm)
AFAIK there's no way to read single chars from a file. You can read lines from the file and use getWord to get single characters though.%line = %file.readLine(); %char = getWord(%line, %LINE_INDEX);
#3
to parse the line, one character at a time. It's a simple loop because the line length will always be the same.
Thanks! :-)
05/01/2010 (4:29 pm)
Ah ha! You guys got me on the right track. I can usegetSubStr(%string, %start, %numChars)
to parse the line, one character at a time. It's a simple loop because the line length will always be the same.
Thanks! :-)
#4
Patrick
05/02/2010 (8:15 am)
If the strings happen to not be the same length for some reason, you can use strlen to loop through.%length = strlen(%newText);
for(%i = 0; %i < %length; %i++)
{
%currentLetter = getSubStr(%newText,%i,1);
}Patrick
#5
05/02/2010 (11:15 am)
Good call Patrick. I would use strLen regardless of whether or not the length is the same. Its the same now, but what about after the Nth revision.
Torque Owner Kevin James
char(string, place, count)
%x = char(%filestring, %n, 1);