Game Development Community

File directory system NOT working

by Kevin James · in Torque Game Builder · 03/30/2008 (7:11 pm) · 13 replies

Hi.

I've been trying to create a function that will execute all the .cs scripts in the gamescripts folder. Here's what I got:

//executeGameScripts("game/gameScripts/") <-- That's the line I call in the console
function executeGameScripts(%folderPath)
{
   %stringPattern = %folderPath @ "*";
   
   %firstFile = findFirstFile(%stringPattern);
   echo(%firstFile);   
   
   for(%i = 0; %i < getFileCount(%stringPattern); %i++)
   {
      echo(findNextFile(%stringPattern));
   }
}

The findNextFile is returning the same value as the findFirstFile, every single time the for loop iterates. Does anyone know how to fix this? In other words, how do you get the findNextFile function to actually find the NEXT file?

Thanks.

About the author

Computer security, digital forensics, and platform jumper enthusiast. shells.myw3b.net/~syreal/


#1
03/30/2008 (8:34 pm)
Try this:

//executeGameScripts("game/gameScripts")
function executeGameScripts(%folderPath)
{
   %stringPattern = %folderPath @ "/*.cs";
   for (%file = findFirstFile(%stringPattern); %file !$= ""; %file = findNextFile(%stringPattern))
      echo (%file);
}
#2
03/31/2008 (8:47 am)
Sweet! Thanks for this, Phil, it works perfectly!

Its the first time Ive ever seen a For loop with something other than %i = a number; etc. Really cool.
#3
03/31/2008 (9:28 am)
That's why he gets the medium-sized bucks!

Phillip's got mad for looping skizzilz.
#4
03/31/2008 (1:35 pm)
And this completes phase two in my plan for total world domination.
#5
03/31/2008 (1:35 pm)
Slightly off topic:
I have a very similar auto-loading script. Oddly enough, today I built a Mac version of my project for a friend. Unfortunately, that same script fails to find any files on the Mac. I don't have a mac and he lives an hour away, so I can't debug why it fails. Any ideas?
#6
03/31/2008 (3:20 pm)
Phillip, David,

Rofl.

Patrick,

Did you try Phil's world domination script above?
#7
03/31/2008 (5:38 pm)
Kevin,
My script is nearly identical to Phillip's, except I pass in a file extension so I can autoload gui files , use "expandFilename" to get the full path, and "exec" (to run the file). None of these seem like they should behave differently on the mac. It works 100% fine on the PC, but not on the mac.

//loadScripts("game/gameScripts", "cs");
//loadScripts("game/gui", "gui");


function loadScripts(%scanDirectory, %scanFileExtention)
{
   %scriptSpec = expandFilename(%scanDirectory) @ "/*." @ %scanFileExtention;
   for (%file = findFirstFile(%scriptSpec); %file !$= ""; %file = findNextFile(%scriptSpec))
	{
		exec(%file);
	}	
}
#8
03/31/2008 (5:52 pm)
David,
Do I get medium sized bucks too?

www.garagegames.com/mg/forums/result.thread.php?qt=57591
#9
03/31/2008 (7:01 pm)
I don't like Macs.
#10
04/01/2008 (6:45 pm)
I like Macs. So is the answer that the other machine that he is compiling it for then has .dso files instead of .cs files, so it never finds the .cs? If so, then even if he developed on a mac and compiled it for windows, it would work on the Mac but not the pc.

Greg
#11
04/02/2008 (4:04 am)
You must build projects for the same platform as you are operating on. You can't build a Windows build of a game from a Mac OS. Is that what you mean by compile?
#12
04/02/2008 (5:57 am)
Kevin,
From the level editor, I am "Building" my project and selecting "Mac" from the Platform drop down. I found the problem - the resulting Mac project includes TGB 1.5. not 1.7. My auto-load script fails because of differences in File I/O in between these versions. If my friend grabs my assets and builds the project from his Mac, the scripts work fine.
#13
04/02/2008 (6:31 am)
@Patrick
No medium sized bucks for you. Only coinage thrown by the unwashed masses.

I wish I got even that!