Game Development Community

Reading individual characters from a variable string

by Konstantin Sch · in Torque Game Builder · 11/20/2008 (12:50 pm) · 2 replies

Hey everybody.

I hope someone in this community can help me with this.
I am an artist by trade and have very limited scripting experience. I've started to learn Torque Scrip to use with TGB, but since the TDN is currently down I've run into a problem which i think must have a simple solution, but I can't seem to find it for the life of me.
You'll probably have a good laugh at this question, but here goes:

I'm scripting a game that created a number of character stats into a two-dimensional Array when first started. It then writes them out into a file for saving purposes.
Now I'm trying to write the function to read those back out into the character array, but for that I need to be able to check the string of the array at a certain position against my separating character.

I guess I'm looking for something along the lines of:

$variableName[x,y].getChar(pos)

Only in real and existing. I'd also greatly appreciate where I can find this info in the reference. I spent a decent bit of time looking for this kind of info.

Cheers and thanks in advance!

About the author

Recent Threads


#1
11/20/2008 (1:06 pm)
Try something like this:

%myChar = getChar($variableName[%x,%y], %charPos);
 
function getChar(%word, %charPos)
{
    return getSubStr(%word, %charPos, 1);
}
#2
11/20/2008 (3:50 pm)
Thank you so much Phil, that function is exactly what I was looking for.
I'll give it a try and if I have any more problems I'll be back.