Game Development Community

Arrays and string manipulation in Torque3D 1.1beta1

by Jules · in Torque 3D Professional · 02/18/2010 (11:50 am) · 3 replies

What's the procedure for creating and obtaining the values of arrays in Torque 3D ? Would the following resource cause any issues if added or replaced by what is already in arrayObjects ? www.torquepowered.com/community/resource/view/4711/4#comments

Is there also such a command to split a string into an array? e.g
%array = strSplit($message, "~");

if $message contained test1~test2~test3

Then call it back via

value1 = %array.getValue(0);
value2 = %array.getValue(1);
value3 = %array.getValue(2);

Does getValue exist in stock Torque, or do I need to go down the c++ route? Just don't want to over complicate things when functionality exists.

Thanks

#1
02/18/2010 (12:21 pm)

There is "NextToken" but be aware that this function modifies the original string so this better not be a string table entry or other shared string. IMO this function shouldn't be there. Modifying strings in place is generally a bad idea.

If you can live with using standard delimiters (tab, space, newlines) it's the easiest thing to go with the standard Torque vector functions. You could have:

%message = "test1 test2 test3";
%array = new ArrayObject();

foreach$( %str in %message )
   %array.push_back( %str ); // or just process directly here

"ArrayObject::getValue" exists in stock Torque.

#2
02/18/2010 (12:26 pm)
cheers Rene. Time to brush up my coding skills again :)
#3
02/19/2010 (4:58 am)
In the end I found it easier to use GetWord(%text, %number).