In JS, When I create static getter/setter, it always gives me this : Assets/src/com/homerun/init/HB_VersionInfo.js(167,32): BCE0020: An instance of type 'HB_VersionInfo' is required to access non static member 'test'. Which makes no sense, since the setter is static. Code (csharp): static public function set test(value:int) { _anotherValue = value;} This method works if it's not static, but obviously not what I want. Pretty annoying. Have an idea ?
Removing the space will make it a function, not a getter/setter. Edit : I.e Code (csharp): MyClass.setTest(value) ; instead of this expected result : Code (csharp): MyClass.test = value;
are you on u3 beta6+? otherwise there is definitely no support for anything like properties / getter setter independent of how you do it. unsure how it works on the new UnityScript as per beta6+
Yeah, I'm using u3 beta 7. I'll check out in the release note or something to see how it work then. I'll post back if I find something. Thanks !
For completeness: On C# it would look like Code (csharp): class test { private static int bla; public static int Bla { get { return bla; } set { bla = value; } } } perhaps that helps
Yeah, I saw that it works on C# in SM2 scripts, that's why I assumed it would also worked on JS. and since the error isn't "syntax error" or something, I guess this will be fixed in the last Unity 3. A similar issue is doing getter/setter in interface, it just don't work either. . Or simply doing interface ! The name of the interface must not equal the name of the file otherwise it don't work. Hope all those things will be fixed... Anyway thanks !
? I thought getter / setter were just mere functions that return or define a variable value, like Code (csharp): function GetHealth () { return health; } function SetHealth (value : int) { health = value;} Have I missed something ?
Nope, thats what they do actually. They are just a more convenient way cause you no longer call them as functions but through "regular value assignements".
When you talk about the space in the function name, you mean when it was written like: "public function set SomeProperty" If so, that's likely coming from Flash's ActionScript. ECMAScript/JavaScript (and therefore UnityScript?), as far as I know do not have getters/setters/properties. ActionScript, based on ECMAScript, added that get/set syntax.
I'm using u3 beta 7, and that get/set syntax works on object instance. No problem at all. But only static one doesn't seems to work. Maybe it's a feature from mono 2.6, dunno...
Ahh, well if they've added that syntax to support instance-level properties, it'd make sense that they'd support static-level properties as well. Guess that should be forwarded to the Unity team to update their UnityScript compiler.
The UnityScript compiler is written in Boo. Therefore, if static property setters and getters work in Boo, there's no technical obstacle to them working in UnityScript. Indeed, static getters do work: Code (csharp): class Aardvark extends MonoBehaviour { static function get whatever () : int { return 12345; } } But, indeed, static setters do not work: Code (csharp): class NoWai extends MonoBehaviour { static function set oRly (value : int) { Debug.Log("You wish!"); } } Googling for "Boo static properties" yields the following bug report: http://jira.codehaus.org/browse/BOO-162, which confirms that the situation is exactly the same in Boo. There's clearly a bug in Boo which hasn't been fixed. My guess is that this has absolutely nothing to do with the UnityScript compiler – there's a good chance that fixing the Boo bug also fixes the UnityScript compiler error. I'm going to file a bug report in Unity, and I suggest you do the same. I have also posted on the Boo language list.