Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

It's not JavaScript, it's UnityScript

Discussion in 'General Discussion' started by coderarity, Feb 3, 2012.

  1. lmbarns

    lmbarns

    Joined:
    Jul 14, 2011
    Posts:
    1,628
    Sorry to bump this but I've been reading some object oriented javascript books unrelated to unity and guess what?????? I see "use strict" cited as why unityscript is different from JS, but strict mode has nothing to do with Unity, it's part of ECMA5, which most modern browsers support natively, and it IS USED outside of unity for javascript based applications.

    Also javascript is classless but it can be used just like any OO language, go buy 2 books called "Javascript design patterns" + "pro javascript design patterns", they're amazing....
     
  2. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    Well it's actually "#pragma strict" in Unity, and has been around since before ECMA5. Regardless, there are way more significant differences than that between UnityScript and web JavaScript.
     
  3. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    Code (csharp):
    1. void test()
    2. {
    3.     var mult = new Func<int, int>(x => x * x);
    4.     var addStr = new Func<string, string>(y => y + y);
    5. }
    Code (csharp):
    1. var isZero = new Predicate<int>(x => x == 0);
    2. var print = new Action<object>(Debug.Log);
    3.  
    4. print(isZero(10));
     
  4. npsf3000

    npsf3000

    Joined:
    Sep 19, 2010
    Posts:
    3,830
    @ Alex - good to see someone else notice the issue with that argument - though me and squidbot have already slaughtered a few villages in our 'debate' :p

    After much though the best I came up with is this:

    Code (csharp):
    1. var mult = function(x : int) {return x * x;};
    2. var addStr = function(s : String) {return s + s;};
    3.  
    4. var mult = function((int x) => { return x * x; });
    5. var addStr = function((string s) => { return s + s; });
    6.  
    7. var mult = function((int x) => x * x);
    8. var addStr = function((string s) => s + s);
    That's right, 'implicit' typing of lambda :p

    Best bit is that once you understand how it works you get the best of both worlds. The ability to create specific delegate types should the API's you call need them, but also a simple generic system that will work in 95%+ of cases. Much like the var itself - works most of the time but you can explicitly type should you desire.
     
  5. illiterate

    illiterate

    Joined:
    Dec 31, 2011
    Posts:
    14
    As a new guy to the forums, and someone with limited exposure to C# and UnityScript, I started out with UnityScript.

    Since then, when I have had to ask around for additional help, all the code i was provided was in C# (the guy who i ask is a C# guy), i found that i wrote better code without all the shortcuts that UnityScript provides.

    Now this might be due to me just starting out, and needing the extra structure it provides, but have moved to C# and am much better off for it.
     
  6. WinningGuy

    WinningGuy

    Joined:
    Aug 10, 2009
    Posts:
    884
    Everyone should just switch to Boo.

    Why?

    Because it has the coolest name.
     
    holliebuckets likes this.
  7. Alec

    Alec

    Joined:
    Mar 11, 2008
    Posts:
    1,330
    I'm going to put my horridly uneducated opinion in here and say :

    This:
    Code (csharp):
    1. yield WaitForSeconds(1);
    Is why I use UnityScript.

    !$#$ing IEnumerator my bum. (enlighten me to other options for the love of shinji)
     
  8. npsf3000

    npsf3000

    Joined:
    Sep 19, 2010
    Posts:
    3,830
    If the biggest problem you face in code is changing void to IEnumerator you've not got any problems worth talking about :p
     
  9. Alec

    Alec

    Joined:
    Mar 11, 2008
    Posts:
    1,330
    It makes me feel lethargic, but alas, I am but a whinging man. :D
     
  10. Ntero

    Ntero

    Joined:
    Apr 29, 2010
    Posts:
    1,436
    Once you realize that you can make your own IEnumerator types, it becomes much more interesting, not so much integrating into Unity's Coroutine system, but to make your own, or create complex collections or buffered utilities.

    Also realizing that yield is a type of return value can help in understanding what it is you are doing with that code. Always good for people learning to code. adding 'return new' to the yield and 'IEnumerator' to the function definition makes sure that what you write maps better to what it is that's created.

    I like concise typing, but I think that hidden functionality and logic, and implied conversions are only going to hurt the beginner, and obscure advanced functionality.
     
  11. squidbot

    squidbot

    Joined:
    Jan 4, 2011
    Posts:
    128
    I had to necro this thread to report that I'm now using C# and perfectly happy :D
     
  12. MarigoldFleur

    MarigoldFleur

    Joined:
    May 12, 2012
    Posts:
    1,353
    Really.

    You had to bring a thread more than a year old back from the grave to tell us what language you're using for scripting?

    You had to?
     
  13. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    Since no kittens get harmed, why not?
     
  14. Khyrid

    Khyrid

    Joined:
    Oct 8, 2010
    Posts:
    1,790
    I love programming in javascript with unity. Javascript is much better than C#, fact. I'm so glad I was able to learn a great language like javascript in unity. Unity's support of javascript is excellent! My favorite thing about the unity supported language called javascript is how it's just better than C#. Also, did you knwo that all the pros use javascript? They do because javascript it great. jaaavvvaaaassscriiiiippppt.
     
  15. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    Last edited: Oct 6, 2015
  16. miguelvesga

    miguelvesga

    Joined:
    Aug 1, 2012
    Posts:
    88
  17. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Great video :D
     
  18. dtg108

    dtg108

    Joined:
    Oct 1, 2012
    Posts:
    1,165
    You.... you monster.....

    but on a serious note, how do people do this? I seriously think that people just skip back 10 pages to find an old thread and open it just to troll.
     
  19. Myhijim

    Myhijim

    Joined:
    Jun 15, 2012
    Posts:
    1,148
    Me also ;)
    Left UnityScript in the dust
     
  20. SevenBits

    SevenBits

    Joined:
    Dec 26, 2011
    Posts:
    1,953
    Search function. Find post. Necro post.
     
  21. marty

    marty

    Joined:
    Apr 27, 2005
    Posts:
    1,170
    So it's settled: Unity JavaScript is better than Unity C#. ;-)
     
  22. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Call it whatever you want, but use it at your own risk because most Asset Store plugins are written in C# and if you want to extend them or ask for support, your sample code will need to be in C#. Why make it harder on yourself?
     
  23. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
  24. dogzerx2

    dogzerx2

    Joined:
    Dec 27, 2009
    Posts:
    3,964
    Lol, and you tell me this like 2 years later?

    Should have switched to C# long ago! Gonna do it first thing I start a new project.
     
    Kiwasi likes this.
  25. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    It is Javascript because it has .js extension and Unity calls it JavaScript internally.
     
  26. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
  27. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
  28. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    This is how they call it "externally".

    And if you actually do this, then
    Capture.PNG
     

    Attached Files:

    Last edited: Oct 7, 2015
  29. jpthek9

    jpthek9

    Joined:
    Nov 28, 2013
    Posts:
    944
    I came from Python so can't relate with you there :c. I whole-heartedly believe that for projects beyond quick and dirty prototype stage, c# is the way to go.
     
  30. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Internally I think Unity Technologies has forgotten the language exists. ;)