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...
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;
Your answer
Follow this Question
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