Game Development Community

Accessing an element in a List?

by Vern Jensen · in Torque Game Builder · 06/17/2006 (12:30 am) · 2 replies

When a function returns a List (such as getWorldLimit()), how do I access the item in the list I want? (For instance, the maxX element from getWorldLimit()'s returned LIst, which would be its 4th item.)

Tried looking in the documentation, but I must be looking in the wrong place...

-Vern

#1
06/17/2006 (1:35 am)
A list is just a space separated string. You can access an element with the getWord(%string, %index) function.

e.g.:
%list = "a b c d";

echo( getWord(%list,0) );
echo( getWord(%list,1) );
echo( getWord(%list,2) );
echo( getWord(%list,3) );

This prints out:
a
b
c
d

The first word has index 0. So in your case you would use getWord(%yourList, 3) to get maxX.
#2
06/17/2006 (11:43 am)
Thanks -- that works great!

I guess it'll take a little getting-used-to that numbers and strings, etc. are interchangeable in Torque... I can use a number that's inside a string as if it's a number.

-Vern