- Home /
problem accesing arrays
Hello. here{s my problem.
I have two objects, ObjectA with scriptA and ObjectB with scriptB.
scriptA has the following.
var array1 =new int[5,9]; var array2 =new int[1];
function Start(){ array1[0,0] = 2; array2[0] = 3; }
and scriptB has the following
var value1 :int; var value2 :int;
function Start(){ value2=GameObject.Find("ObjectA").GetComponent("scriptA").array2[0]; value1=GameObject.Find("ObjectA").GetComponent("scriptA").array1[0,0]; }
value2 sets correctly at 3, but value1 gets the following error:
MissingFieldException: Field 'System.Int32[,].' not found.
What could be the problem?? thank you
Answer by Eric5h5 · Mar 27, 2011 at 05:52 PM
It's better not to use strings with GetComponent (faster, plus you get compile-time errors instead of runtime errors), also using generics is a simple way to avoid dynamic typing, which for some reason causes problems with multi-dimensional arrays.
value2 = GetComponent.<ScriptA>().array2[0];
value1 = GetComponent.<ScriptA>().array1[0,0];
Thanks a lot. this solved my problem, altough i didnt understand why it worked!
Never$$anonymous$$d! now I understand! thanks for helping me!
Answer by Justin Warner · Mar 27, 2011 at 05:46 PM
Is value1 supposed to be accessing a 2D array? If so, it wouldn't be an int (Up top at the initializing), I believe. So I'd guess the problem is you're making value1 and int, but it can't be an int, because it's holding 2 values from the array.... If that makes sense.
Comment for further help.
Hope this makes sense, and good luck!
No, a single value from a multidimensional array is still an int; that's not the problem here.
Your answer
Follow this Question
Related Questions
Get ParticleSystem (Shuriken) to play from array of game objects C# 2 Answers
How to find the index of an Object in an Array 2 Answers
Advance through array elements with math (++)? 1 Answer
Attempt at creating an array of text files results in different errors 1 Answer
2D Array keeps coming up as Null 1 Answer