- Home /
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:
print("textureArraySize is " + textureArraySize); private var textureArray = new Texture[ textureArraySize ]; print("textureArray length is "+ textureArray.lenght);
@ kevork: ok, I just added the code for CountResources() that is from FileIOTools.js file.
@aldonaletto: when I add print out the textureArray.length for the array when it is initialized with a hard coded value(39) it prints that value(39), when I use the variable:int that has that value(39) it prints out (0). I guess the thing I could try is to just make a variable that stores a hard coded int and make sure that it executes that way. I'll give that a shot.
Answer by loopyllama · Oct 01, 2011 at 07:54 AM
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.
Thanks for you response. The CountResources function is returning an int.
I tried "Int32.Parse()", "int32.Parse()", but only "int.Parse()" seemed to execute. However, I received this error when I updated the code to parse it as an int.
Assets/ghscripts/PrefabTools.js(77,28): BCE0023: No appropriate version of 'int.Parse' for the argument list '(int)' was found. I updated the code above to contain the code for CountResources.
Your answer
Follow this Question
Related Questions
passing a javascript array into a function sorts it? 1 Answer
Accessing a Variable From Another Script 2 Answers
Cycling Texture Array 1 Answer
Add a temporary variable to an array 1 Answer
Array Problem - Error Code BCE0022 1 Answer