Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Grasshorse · Sep 30, 2011 at 06:33 PM · texturearrayvariablefunction

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

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kevork · Sep 30, 2011 at 09:45 PM 0
Share

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

avatar image aldonaletto · Oct 01, 2011 at 02:01 AM 0
Share

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);
avatar image Grasshorse · Oct 01, 2011 at 04:36 PM 0
Share

@ 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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Grasshorse · Oct 01, 2011 at 04:27 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges