Object object (data object) in Unity? Or is it Hashtable?

Hi, in Flash as3 I’d commonly do something like this:

var obj:Object= {lx:32,ly:99};
print (obj.lx);

or

var obj:Object = new Object();
obj.lx = 32;
obj.ly = 99;
print (obj.lx);

And my experience and research with javascript tells me this should work in javascript as well. But in unityScript it gives me an error like

lx is not a member of ‘Object’

It seems with some experiment that unity wants this to be a Hashtable? Does the Object object not exist in Unity as it does in Javascript or As3? I can’t even get Hashtable to work as expected, get similar error.

LOL.

Either you define a type - e.g.:

struct LOL {
public int x;
public int y;

public LOL (int x, int y)
{
this.x = x;
this.y = y;
}
}

//

LOL lol = new LOL(10,5);
print(lol.x);

Use an existing type that’ll work:

var lol = new Vector2(10,5);
print(lol.x);

Learn to use dictionaries correctly: [Hint, this is probably a bad use-case]

var lol = new Dictionary<string,int> {{"x", 10},{"y", 5}};
print(lol["x"]);

or learn about C# anonymous types:

var lol = new {x = 10, y = 5};
print(lol.x);

(By and large untested C# code)

It’s not a ‘function’ - that’s code. This is just a way of storing data.

Array is there to be used.

Not a problem.

Just remember that Unity-Script is a compiled language, while JS/AS are interpreted. From the looks of it your AS3 example uses late binding which is a no-no. Though, anonymous types are fine as I’ve demonstrated.

Oh, and I’m not a US guru so there is a small chance someone’ll pop up with a feature I’m not aware of. Just don’t hold your breath.

Well, UnityScript is not ActionScript obviously, neither it’s JavaScript. UntiyScript is actually more of a programming language, not a scripting language, so you’ll have to work with defined classes or structs.

Gues it’s time to grow up and learn programming not just scripting :slight_smile:

To anyone else who reads this some of the question was answered here:

http://forum.unity3d.com/threads/54747-Javascript-vs.-Unityscript