Problem with findFirstFile and findNextFile in TGB 1.5.1
by Aleksey Linetskiy · in Torque Game Builder · 08/27/2007 (9:18 pm) · 6 replies
Hi,
I am trying to migrate my project from 1.1.3 to 1.5.1. I found several problems - here is one of them.
I have the following code:
exec("~/gameScripts/scriptA.cs");
// load other scripts
%filePattern ="~/gameScripts/addlScripts/*.cs";
%fname = findFirstFile(%filePattern);
while ("" !$= %fname) {
echo ("Loading script from file " SPC %fname);
exec(%fname);
%fname = findNextFile(%filePattern);
}
In gamescripts/addlScripts I have several script files which I want to execute. In 1.1.3 this code executed correctly. In 1.5.1 the scriptA.cs is loaded OK, but findFirstFile doesn't find anything. If I change the pattern to just "*.cs", it will list all the script files in all subfolders. Did anyone encounter something similar?
I am trying to migrate my project from 1.1.3 to 1.5.1. I found several problems - here is one of them.
I have the following code:
exec("~/gameScripts/scriptA.cs");
// load other scripts
%filePattern ="~/gameScripts/addlScripts/*.cs";
%fname = findFirstFile(%filePattern);
while ("" !$= %fname) {
echo ("Loading script from file " SPC %fname);
exec(%fname);
%fname = findNextFile(%filePattern);
}
In gamescripts/addlScripts I have several script files which I want to execute. In 1.1.3 this code executed correctly. In 1.5.1 the scriptA.cs is loaded OK, but findFirstFile doesn't find anything. If I change the pattern to just "*.cs", it will list all the script files in all subfolders. Did anyone encounter something similar?
About the author
#2
08/29/2007 (8:54 pm)
Thanks! It helped!
#3
For example:
An optional second parameter allows specifying the type of script, which defaults to *.cs. For example:
Or you might need *.gui, I forget.
loadDirectory() also correctly deals with the case where there are dsos but no scripts. The code you pasted will not work in that situation.
T.
08/29/2007 (10:11 pm)
There's already a script function for loading a directory of scripts. It's defined in common somewhere, I forget exactly where.For example:
loadDirectory(expandFilename("~/gameScripts/addlScripts"));An optional second parameter allows specifying the type of script, which defaults to *.cs. For example:
loadDirectory(expandFilename("~/gui"), "gui");Or you might need *.gui, I forget.
loadDirectory() also correctly deals with the case where there are dsos but no scripts. The code you pasted will not work in that situation.
T.
#4
Unable to find function loadDirectory
Am I doing something wrong?
08/30/2007 (8:35 pm)
When I tried using this code, I've got the following:Unable to find function loadDirectory
Am I doing something wrong?
#5
08/31/2007 (10:41 am)
LoadDirectory is defined in the editor, but the file is not copied into the game. I believe it's called 'fileLoader'. Just copy the file and exec it in your game folder and you'll have it defined.
Torque Owner DragonSix