- Home /
Simple Array Problem
Im Trying To Create A Simple Array Of GameObjects In JavaScript, I Wrote The Simple Code And It Worked The First Time. Then I Decided To Change The Name Of The Variable Holding The Array And I Had This Error:
"The best overload for the method 'UnityScript.Lang.Extensions.get_length(System.Array)' is not compatible with the argument list '(int)'."
So After That I Undid What I Had Done Saved It Out And Still Had The Error With The Same Exact Code I Started With That Worked The First Time!
Here Is The Simple Code:
var GameObj : GameObject[];
function Update () {
for (var i=0; i < GameObj.length; i++) {
GameObj.length[i]; // It Says The Error Is On This Line
}
}
Thanks For The Help, This Is Really Aggravating Haha
Answer by Berenger · Jan 30, 2012 at 03:15 AM
You must understand the difference between those two things :
length is a function that returns the number of elements in your array. You mustn't add [] or () after.
GameObj[ INDEX ] is an actual member of that array, at the index INDEX. That's what you need to use.
And just a piece of advice, GameObj for a name of array seems a bit confusing. Try a minuscule for the first letter of variables in general, and a plural for arrays. But that's up to you.
Your answer
![](https://koobas.hobune.stream/wayback/20220613063532im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Writing certain values of an array into a different array 3 Answers
displaying playerprefs 1 Answer
Increasing And Decreasing An Array Through A Variable 2 Answers