Returning an array from a function
by Rob Segal · in Torque Game Builder · 10/09/2006 (1:07 am) · 2 replies
So I have this function I made getFileList (isn't this in the engine already?). My problem is that when I interpret the return value from this function it's empty. It's like it's not array at all. Am I doing something wrong here? Surely I am lacking some sort of script line because I would think this should work. Any thoughts?
function getFileList(%path)
{
%file = findFirstFile(%path);
%i = 0;
while (%file !$= "")
{
%fileList[%i] = %file;
%file = findNextFile("~/data/levels/*.*");
%i++;
}
return %fileList;
}
#2
This works. My only gripe is the way I have to reference objects out of that SimSet afterwards as...
as opposed to...
But that really is a small detail that I can live with.
Hehe... yep you're absoloutely right. That literal string should be %path like in the call to findFirstFile. Thanks for the help Ben.
10/09/2006 (11:01 am)
Ah right. I'd forgotten that %fileList is different from %fileList[0] in Torque script. Here is a revised version I made using a SimSet... function getFileList(%path)
{
%fileList = new SimSet();
%file = findFirstFile(%path);
while (%file !$= "")
{
%fileList.add
(
new ScriptObject()
{
fileName = %file;
}
);
%file = findNextFile(%path);
}
return %fileList;
}This works. My only gripe is the way I have to reference objects out of that SimSet afterwards as...
echo("Level file name is " SPC $levelList.getObject(0).fileName);as opposed to...
echo("Level file name is " SPC $levelList[0]);But that really is a small detail that I can live with.
Quote:Your code makes a list of files where the first file is from %path and the rest are from the levels dir? Hardly seems like what you would want to do ;)
Hehe... yep you're absoloutely right. That literal string should be %path like in the call to findFirstFile. Thanks for the help Ben.
Torque Owner Ben R Vesco