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 /
  • Help Room /
avatar image
0
Question by Artis_ · Apr 07, 2016 at 08:48 PM · javascriptarraygetcomponent

Problem to read an array from another script but on the same object

i have create an array for store some name that i create and it actually work

 for(i=0;i<100;i++){
     for (var z:int=0;z<Random.Range(2,4);z++){
         
         nome += firstNameSyllables [Random.Range(0,  firstNameSyllables.length)];
         
     }
     arraynomi.Add(nome);

and "arraynomi" have something inside if i type

 for (var value : String in arraynomi) {
                 print(value);
             }

so for sent the array to the other script (in js/unity script) i use

 GetComponent.<star_clone>().nomistella = arraynomi;

the 2 script(star_clone) is on the same object, so get component alone i think is right. But probably not becouse the array (nomistella) in the 2° script is empty, and the fun things is that it worked before i go to dinner xD. All in unity script. Thanks for the help :3

Ah and when unity tell me that the array is empty it tell me this:

 ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count.
 Parameter name: index
 0
 System.Collections.ArrayList.ThrowNewArgumentOutOfRangeException (System.String name, System.Object actual, System.String message) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections/ArrayList.cs:3261)
 System.Collections.ArrayList.get_Item (Int32 index) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections/ArrayList.cs:2652)
 UnityScript.Lang.Array.get_Item (Int32 index)
 star_clone.Start () (at Assets/Solar System/star_clone.js:58)

i know the error, if i try to access an empty array is obvious that there is an error, what i don't understand is why my code for pass the array is wrong...

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by toddisarockstar · Apr 08, 2016 at 06:05 AM

if the lookup is your problem, i found that some ways to state a script lookup only work for certain platforms. IDK this is the only way that i found that works for any platform and in any section of your code for javascript. i know its kinda weird but it always works even if you want to do the lookup at the top of your code.

 var otherscript: nameofotherscript=GetComponent(nameofotherscript);
        otherscript = GetComponent(nameofotherscript);
 
        otherscript.othervariablesomewhere=whatever;
 

Comment
Add comment · 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

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

71 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Randomized array result from other scipt 2 Answers

How do I use arrays, with getcomponent? 2 Answers

flashlight on and off 1 Answer

Array problem 1 Answer

How to loop to get all rigidbodies & rendercomponents? 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