It's not JavaScript, it's UnityScript

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

  1. lmbarns

    lmbarns

    Member

    Joined:
    Jul 14, 2011
    Messages:
    1,316
    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

    Member

    Joined:
    Dec 13, 2009
    Messages:
    2,964
    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

    Member

    Joined:
    Nov 20, 2010
    Messages:
    813
    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

    Member

    Joined:
    Sep 19, 2010
    Messages:
    3,773
    @ 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

    New Member

    Joined:
    Dec 31, 2011
    Messages:
    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

    New Member

    Joined:
    Aug 10, 2009
    Messages:
    886
    Everyone should just switch to Boo.

    Why?

    Because it has the coolest name.
     
  7. Alec

    Alec

    New Member

    Joined:
    Mar 11, 2008
    Messages:
    1,331
    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

    Member

    Joined:
    Sep 19, 2010
    Messages:
    3,773
    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

    New Member

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

    Ntero

    New Member

    Joined:
    Apr 29, 2010
    Messages:
    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

    Member

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

    MarigoldFleur

    Member

    Joined:
    May 12, 2012
    Messages:
    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

    Member

    Joined:
    Nov 20, 2010
    Messages:
    813
    Since no kittens get harmed, why not?
     
  14. Khyrid

    Khyrid

    Member

    Joined:
    Oct 8, 2010
    Messages:
    1,699
    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

    Member

    Joined:
    Nov 20, 2010
    Messages:
    813
  16. miguelvesga

    miguelvesga

    Member

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

    Dantus

    Member

    Joined:
    Oct 21, 2009
    Messages:
    3,933
    Great video :D
     
  18. dtg108

    dtg108

    Member

    Joined:
    Oct 1, 2012
    Messages:
    1,168
    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

    Member

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

    SevenBits

    Member

    Joined:
    Dec 26, 2011
    Messages:
    1,956
    Search function. Find post. Necro post.