as far as I know it this can be done in javascript:
personObj=new Object();
personObj.firstname=“John”;
personObj.lastname=“Doe”;
personObj.age=50;
personObj.eyecolor=“blue”;
but I can’t do it in unity? I get an error message?
anyone?
Peter
as far as I know it this can be done in javascript:
personObj=new Object();
personObj.firstname=“John”;
personObj.lastname=“Doe”;
personObj.age=50;
personObj.eyecolor=“blue”;
but I can’t do it in unity? I get an error message?
anyone?
Peter
personObj = Object();
personObj.firstname = "John"
personObj.lastname = "Doe"
personObj.age = 50;
personObj.eyecolor = "blue"
There is no new keyword (or at least if there is, it is not used in this way) in javascript.
Something is NOT javascript in unity3d… some of the most basic stuff that can be done in javascript can not be done in Unity
example
var obj = {
groupName : “hello”
}
somebody please tell me what is going on? is this javascript or just a unity “want to be javascript”?
Peter
what errors are you receiving?
UnityScript is not equal to the playin old original JavaScript, even if it looks like:
Iam not even sure that UnityScript supports fully dynamic typed types.
I would prefer to create a class for that or use C# which supports anonymous classes (but you would rarly use it).
Creating a well defined/declared class has the positive aspect of beeing more readable than some duck typed class. IMHO
It is “want to be javascript”. In fact, it has very little in common with javascript at all. It just shares some of the syntax. This is why you will often see Unity’s javascript referred to as ‘UnityScript’.
Actually Javascript as UnityScript are both some real world incarnation of the more or less same standard, ECMA Script, on a different level of it (with javascript as in browser being primarily procedural, while unitys is pure OO)
can someone please explain to me how to do what I want?
how do I create a
var obj = {
groupName : “hello”
}
and access it using:
obj.groupName
I’m going crazy using the non standard javascript from Unity3D (UnityScript is a much better name)… calling it Javascript is just plain stupid when it’s not javascript
Peter
ok. nevermind…
I can see that UNITYSCRIPT (aka javascript) … has a primitive form for a class
and there goes the prototypes from the javascript world… so sad
Peter
Using classes in Unityscript is nicer than prototype stuff. http://www.unifycommunity.com/wiki/index.php?title=Head_First_into_Unity_with_JavaScript
–Eric
I don’t really care if it’s classes or protypes … my day was ruined when I found out that Unity Javascript has actually nothing to do with javascript… they should have called it something completely different and just announce that the language resembles javascript.
Peter
I really don’t see how it is that big of a deal… It’s really close to JS, and if you are even remotely good programmer, you would be able to adapt very quickly…
well we differ in opinions… I don’t care if I’m the best or worse programmer in the world… the fact is… it is not javascript, but it is called javascript in unity…
I know javascript and because I was lead to believe it was javascript I expect the same paradigm when programming, which means I structure my code to utilize what javascript can… I have used my whole day now to tear down everything I have created and restructured it to support the UnityScript (aka. javascript) paradigm with classes instead… pain in the ass… if I knew this from the start I would have saved a whole days work.
I am adapting, I can program in C/C++, Python, Javascript, Php, Pascal and many more… read my resume here: http://www.marino.dk/resume/
anyways… I just hate the fact that they call it javascript… that side tracked me… it is not javascript.
Peter
Can’t agree with that…it’s more like JScript.NET or Actionscript 3, and it has more in common with C# than it does with JS. It’s even less like web Javascript than ever in Unity 3, and I think it’s about time the name was officially changed to Unityscript.
–Eric
While I do agree that the name should be officially changed, I really don’t see how it is that big of a deal; especially if you are able to adapt as you say. Actually, if you already know Java, then I would just forget about unityscript and go for C# as both the syntax and underlying concepts are almost identical (C# is actually closer to java than it is C++ other than the way it is compiled).
think you are missing the point of this thread…
on a side note… Unity3D recommends that we use javascript (so that is what I’m doing)
Peter
Sorry for going off topic.
At any rate, what is the point of this thread? I am officially lost now.
The people in the know have been calling it UnityScript for quite a while, so it’s semi-semi-official.
and it’s just Unity now, not Unity3d. lol