Game Development Community

Load from a directory?

by Kirk Sigmon · in Torque Game Builder · 10/30/2005 (4:32 pm) · 2 replies

I've been trying to implement a Datablock system for my game that scans all image files in a folder and converts them to datablocks for use. I know this is simplistic and problematic, just bear with me.

Anyway, I've come up with the following code. It seems sound to me, but torque keeps coming back with the (included) error message. Is there something wrong with this code, or is it just a generic torque thing?

function BodyLoad()
{
   %FileSpec = "~/client/data/body_*.png";
   %Target = FindFirstFile(%FileSpec);
   %begstring = "~/client/data/body/";

   while (strlen(%Target) > 0){
	datablock fxImageMapDatablock2D(%Target){
      		     mode = cell;
      		     cellWidth = 32;
     		     cellHeight = 48;   
		     textureName = %begstring %Target;
	         };   
         %Target = FindNextFile(%FileSpec);
      }
}

Quote:T2D/client/loadall.cs Line: 8 - Syntax error.
>>> Advanced script error report. Line 15.
>>> Some error context, with ## on sides of error halt:
while (strlen(%Target) > 0){

^datablock fxImageMapDatablock2D(%Target)##{##

^^ mode = cell;

^^ cellWidth = 32;

^^ cellHeight = 48;
>>> Error report complete.

#1
11/02/2005 (3:13 pm)
I think you cant declare a datablock with a variable...

Try
%datablock = new fxImageMapDatablock2D(%Target);
%datablock.mode = cell;
...ETC....

OR

eval("datablock fxImageMapDatablock2D(" @ %Target @ ") { mode = cell; cellWidth = 32; cellHeight = 48; textureName = %begstring %Target; };");

Tell me if you have any luck, second one is most likely to work. =)
#2
11/02/2005 (6:03 pm)
You mean something like this :)

T2D Image Datablock Tool V1.2