2

I am using Unity3D 4.2 and have a button to trigger this:

function SubmitMove()
{
p1cube = new Array ();
p2cube = new Array ();
    var allCubeList = GameObject.FindGameObjectsWithTag("cube");
    for(var allCube: GameObject in allCubeList) 
        {
        if(allCube.GetComponent(CubeARDP).cubeState == "1")
        {
        p1cube.Push(allCube.name);
        }
        else if(allCube.GetComponent(CubeARDP).cubeState == "2")
        {
        p2cube.Push(allCube.name);
        }
        }

}

So how the p1cube.Push(allCube.name); give me some error:

MissingMethodException: System.String[].Push
Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.ProduceExtensionDispatcher ()
Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.Create ()
Boo.Lang.Runtime.RuntimeServices.DoCreateMethodDispatcher (System.Object target, System.Type targetType, System.String name, System.Object[] args)
Boo.Lang.Runtime.RuntimeServices.CreateMethodDispatcher (System.Object target, System.String name, System.Object[] args)
Boo.Lang.Runtime.RuntimeServices+<Invoke>c__AnonStorey15.<>m__9 ()
Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.DispatcherKey key, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args)
UnityScript.Lang.UnityRuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args, System.Type scriptBaseType)
axisrotateDynamicParenting.SubmitMove () (at Assets/component_tested/axisrotateDynamicParenting.js:468)
axisrotateDynamicParenting.OnGUI () (at Assets/component_tested/axisrotateDynamicParenting.js:285)

Any idea what is going on?? I checked Unity script reference that whatever I do seems to be OK. Any help will be great. Thanks!

0

1 Answer 1

1

It looks like p1cube is not a regular JS array there; somehow, you have a native .NET array. Those aren't resizable, and thus don't have a Push method (because "pushing" by definition makes the array longer).

I'm parsing through the docs right now, so forgive my guessiness. But it appears that if the array is declared as String[], then it'll be a fixed-size, native .NET array. In order to do what you want, you could either declare the two arrays as Array, or have your functions create their own local JS arrays that you turn into String[] once you're done adding stuff.

As for how/why you could smuggle an Array into a variable declared as String[]? I haven't a clue. But JS's type system is somewhere between "very dynamic" and "I just changed what Object means". Maybe that's playing a part.

Sign up to request clarification or add additional context in comments.

3 Comments

How can I add a JS Array specifically? I just var p1cube : String[]; when declare the array.
@sooon: If i had to guess... var p1cube : Array;. But i have literally never even seen Unity Script before, so that's just what it is -- a guess. :P
I declare my array into this: var p1cube = new Array( [ ] ); and it works. I found the solution from this. Thanks for your insight @cHao, you save my day :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.