variable with int value not passing to command

Having troubles here with a little bit of code. I must be missing something obvious. I have a function that I am calling, CountResources, the return value of which I am storing as textureArraySize:int. The value returned from CountResources function is 39. When I hard code 39 into the last command below a Array of textures is created with the length of 39. When I try and pass the variable textureArraySize (which is set to 39 as an int) to the Array creation code, I get a length of 0. Anyone see anything that would be causing this issue?

Best Regards,

Steve

stringPattern = ".png" ;

var textureArraySize:int;
textureArraySize = FileIOTools.CountResources(stringPattern);
print("textureArraySize is " + textureArraySize);
private var textureArray = new Texture[ textureArraySize ];
// private var textureArray = new Texture[ 39 ];

    
static function CountResources(stringPattern)
    
{
	var arrayCount: int = 0;

	for (file in fileInfo)
		{
			fileNameAndPath = file.ToString();
		    if (fileNameAndPath.IndexOf (stringPattern) != -1)
		    {
		    	arrayCount++;
		    }
		}
	return arrayCount;
}

EDIT: Ok, here is some test code that I can’t figure out the logic of, and I think it is the spot where the problem occurs.

var test:int;
test = 35;

private var testArray = new GameObject[ test ];
// private var testArray = new GameObject[ 35 ];

print("testArray.Length is " + testArray.Length);

OK, first execute that code. If you uncomment the commented out line, and comment out the one above it and execute it again you will see that the length turns from 0 to 35. All ideas are welcome!

Best Regards,

Steve

Probably want to include the code from FileIOTools::CountResources()

Nothing seems wrong with this code. Try to add another debug line after the array creation just to be sure: <pre> print("textureArraySize is " + textureArraySize); private var textureArray = new Texture[ textureArraySize ]; print("textureArray length is "+ textureArray.lenght); </pre>

1 Answer

1

perhaps the 39 it returns is not an int but the string “39” which would be 0 when implicitly converted to int textureArraySize. try casting the result from CountResources to an int like this:
textureArraySize = Int32.Parse(FileIOTools.CountResources(stringPattern));

if that works, maybe you should return an int rather than a string from CountResources.

the code formatting button seems broken on my browser. apologies.