Does Unity javascript supports structures?

Hi guy.
Does unity javascript support c++ structures and classes. How to define global variables and/or structures/classes. I was looking for a usefull way to store data in an encapsulated form. And better yet to have some global data to be common for use by multiple game objects. Javascript.

Do3D.

If a variable is public then it’s global (JS is public by default):

var foo : int;

Class:

class MyClass {
  // stuff
}

Struct:

class MyStruct extends System.ValueType {
   // more stuff
}

–Eric

Thanks Eric5h5.

Vexingly, it looks like structs should be supported: Download Archive

“New UnityScript compiler: generics, interfaces, structs, type cast operator, anonymous functions/closures, lambda expressions, function types, type inferred array comprehensions and more.”

However, if they are supported, the keyword is not struct, I just tried it and got a compile error.

They are supported, see my post above. I’d like to know about that type cast operator though; can’t find anything about that, as it doesn’t seem to be covered on the update page.

–Eric

I don’t know that I’d call extending ValueType “support” for struct, I read that as being syntactically supported. But that’s just quibbling :slight_smile: I do wonder if they use some funky syntax like the generic support where you need the extra dot (i.e. list., ugh I hate that)

Well, it’s how structs are declared in JS. It’s not actually new to Unity 3, but using “override” is; see here: http://unity3d.com/support/documentation/Manual/MonoUpgradeDetails.html.

–Eric

Ah hah, I found the page that covers the language additions:

http://unity3d.com/support/documentation/Manual/MonoUpgradeDetails.html

Eric5h5 was spot on, though I would hardly call that “language support” :slight_smile: