How to create in array variable in JS/unityscript?

I’m getting an error and I don’t know how to get rid of it. I think I can set the values in Start() but I want t learn how to do it this way just for my knowledge.

var input : Array = {u,ur,r,dr,d,dl,l,ul};

function Start()
{

}

I think what I’m doing wrong is that I’m not specifying which type of value is inside of the array(string, float, int, etc). but I don’t know how to do this.

I also tried this with no luck

var input : String[] = {u,ur,r,dr,d,dl,l,ul};

I feel you will benefit tremendously from these tutorials: [Unity Beginner Scripting][1] [1]: http://unity3d.com/learn/tutorials/modules/beginner/scripting

–

That's where I just came from.

–

1 Answer

1

The second format is correct - but I’m assuming u, ur etc aren’t variables but the string you want:

     var input : String[] = ["u","ur","r","dr" ];

Use [ and ] not { and }

.... great, LOL.

–

Actually I still have the same error. Do I have to create each of those string variables separately?

–

I'm an idiot - hang on updating the answer...

–

From the tutorial videos. Is {} c# specific? [22568-capture.png|22568]

–

Yep that's the csharp syntax (which got us both confused :)

–