Search Unity

How should I learn Javascript???

Discussion in 'General Discussion' started by Kman43759, Feb 20, 2015.

Thread Status:
Not open for further replies.
  1. Kman43759

    Kman43759

    Joined:
    Nov 16, 2014
    Posts:
    5
    I know the basics to Javascript, and a little bit more... But I don't exactly know where to go to just specifically learn about Javascript for Unity, where would you guys suggest I go?
     
  2. R-Lindsay

    R-Lindsay

    Joined:
    Aug 9, 2014
    Posts:
    287
  3. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    2,640
    Go through the API page by page if you know javascript or actionscript already. C# may mangle your brain a bit if you want to jump right in. UnityScript makes things like yield WaitForSeconds (secondsVar) syntactic sugar and you won't have to write extra functions doing a two and a half somersault backwards flip to make it work..just one line of code. I went from AS 2&3 to being able to code in UnityScript in just one long evening of messing about due to the similarities the day I downloaded it in 2009. Once you have that under your fingers the transition to C# will make more sense. The link to the blog contains many folks who champion UnityScript BTW..for the exact same reasons I use it. I can write C# but it is too verbose in some cases so I don't bother with it unless working with others who have established a C# base framework..and only to satisfy their prejudices.. If I am writing it I go straight for UnityScript...literally for me a no-brainer.
     
  4. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    14,300
  5. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    2,886
  6. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    14,300
    Schneider21 likes this.
  7. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    2,640

    And if you want to learn UnityScript use the API and parse the examples. You DO NOT have to use C# to write game code. You DO NOT have to write C# to use C# assets. You C# folks are a bit much sometime. The language is based on C and hence the backflips to do simple stuff (not to mention that MicroSoft headspace).. UnityScript was built to write games with and that is a fact..
     
    QuackProductionz likes this.
  8. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    14,300
    One could argue the same thing about UnityScript. It is JavaScript that has been twisted to fit the .NET/Mono framework.
     
    calmcarrots likes this.
  9. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    2,640

    True.. But the original question..though mentioning JavaScript was to be parsed as learning UnityScript.. Not be dragged down C# alley and bogus comments as to why they should bang their head against the wall a few dozen times before proceeding to do anything with the engine. The comments on the blog are telling to be sure with most replies in favor of UnityScript (much faster prototyping) and the peppering of C# and Boo/Python guys with some of the C#-ers doing that always annoying thing of asking UnityScript to be deprecated altogether..including hippocoder <smack!>. If I had downloaded Unity way back when and it was necessary to script in C# I would never have used it and it would have headed for the Trash. Fact was I had a library of physics constraints, movers, rotators and animators built in hours because the transition was simple for me from an ECMA styled scripting language and I understood rigid bodies and physics from setting up countless sims in Cinema 4D. I get paid by the job. If I have to dig around the MS dev site to find C# stuff there goes my pay on a downhill run on a per hour rate that I estimated and bid a fixed price based on how long it would take me times 35 bucks an hour.
     
  10. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,452
    Short answer: There is nowhere to go.

    UnityScript is a Unity only resource. Unity has not provided documentation for their implementation of anything that is not related to the Unity API. Best bet for learning UnityScript is to read the examples in the docs, as previously mentioned.
     
  11. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473
    You could buy one of the Unity books that works with Unity JS. Still more around than for Unity + C#.
     
    Kiwasi likes this.
  12. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    2,886
    And the debate rages on...

    @ippdev I've actually defended UnityScript here previously. I started off using it and learned that C# was a better fit for my preferences. Really, when it comes down to it, it's all about preference.

    However, if you're looking to learn from a base level, it's my personal opinion that learning C# over UnityScript is a better option. Learn C# for Unity and you more-or-less know C#! It's not a far jump to pick up any other programming language from there. UnityScript is in a weird sort of middle ground that it's easy enough to form some bad habits, maybe... and even learning that, you wouldn't even really be a better JavaScript programmer afterwards since the languages are different enough.

    But again... it's really just preference.
     
    Devil_Inside and Ryiah like this.
  13. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    2,640

    What bad habits? More C# baloney and boogeyman stories for the uninitiated. Ever heard of #pragma strict? Typing your variables? Two very simple nearly mindless things to do that eliminate the so called bad habits...and who says someone wanting to learn UnityScript necessarily has any use for C# in another context. What use is IEnumerator good for in JavaScript or ECMA/AS2&3 scripting. Gimme my function and var and no having to talk like Yoda any day of the year. I am on OS X and C# is practically useless to me and the dozens of things I do daily for cash on my computer..Apple dropped the C linkage with Swift. Praise Jesus! I do know C from programming Arduino microcontrollers. In Unity I "talk" to them with UnityScript.
     
    Last edited: Feb 20, 2015
  14. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,452
    Many users haven't and this feature of the language means the can ignore typing. Until it turns around and bites them.

    Pragma strict does have the effect of making your scripts almost as verbose as C#.

    I do like some of the features, like automatic coroutines. The shorter syntax doesn't really do anything for me, but I can see why people like it.

    My main reason for going C# these days is the greater level of control. It is a slightly lower level language then UnityScript. You can achieve the same control in UnityScript, you just have to know what you are doing. As there is no definitive documentation for UnityScript this is a deal breaker for me.
     
  15. calmcarrots

    calmcarrots

    Joined:
    Mar 7, 2014
    Posts:
    681
    I feel as if JavaScript is a dirty language. Honestly, c# is much better. It is more fun to program in because of its flow. I believe it is easier. JavaScript is filled with annoying colons, weird syntax, and it's just weird
     
  16. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    14,300
    My only real complaint about UnityScript is a general lack of resources. It may be based on JavaScript but there are enough differences that it may as well be treated as a different language. Someone who is knowledgeable on programming can pick it up, but then they should be capable of picking up any language.

    Unity's own learning resources are not even based on UnityScript any more but rather on C#. We also have a very popular free book covering it as well.

    These factors make it impossible for me to recommend UnityScript to anyone.
     
    Devil_Inside and Kiwasi like this.
  17. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    2,886
    Important to distinguish between JS and US, though, I think. I like Javascript (and for the record, have nothing against UnityScript, I just prefer C#), even though its prototypal inheritance model is such a foreign and strange concept.

    @ippdev Pragma strict and variable typing are actually exactly what I was referring to. In fact, back when I was working with UnityScript to learn, some "answers" I'd find to problems I was running into were "Delete #pragma strict from the top of your file and that should remove the error." Reminds me of when people suggest on SO to set your file permissions for Apache sites to 777 to fix issues. You don't find this kind of behavior with C# code because it enforces better code is all.

    Didn't mean to offend you, though. Just trying to provide a recommendation for a novice coder.
     
  18. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    2,640
    I never had an issue where I had to delete #pragma strict and it is a part of each script created within Unity from the right click Create menu. I always type my variables. I have to write three functions..two voids and an IEnumerator to use a yield in C# and one line to make it work in US..tell me again about verbose. The OP asked about where to learn US.. Not C#. Pointing OP via grand proclamations about C# saying it is THE language to code games in who said OP has some knowledge to get up and running with the Unity engine with US because he does know some JS is simply C# snobbery..which is rife around here. What low level stuff can you do in C# that matters for a noob or an intermediate can you not do in US? I ain't run into it in creating 60+ games and subsystems for clients. I think it is a bogus claim. Prove me wrong.
     
    Tiles likes this.
  19. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473
    Why do you feel the need to recommend C# in a JS thread at all where the OP already did his choice? The OP asked for help with JS, not with C#.

    The word novice coder triggers me. So ...

    JS != Novice coder
    C# != professional coder

    A professional is somebody who uses what meets the requirements and what does the job best. In Unity this can be C#, but this can also be JS. Or Playmaker. And outside of Unity you have the choice between hundrets of engines with dozens of languages between Basic up to C / C++. Heck, i know even people making money with games made with Yoyo Gamemaker or Construct without real programming at all.

    Everything working is allowed. And a professional lone wolf, where the manpower is the limiting issue, and AAA out of reach anyways, better uses the for him easiest possible tool to reach the goal. Not the most powerful one. This can save months of work at a project. And time is money. One of the reasons why Unity is so popular by the way, compared to other even more powerful engines. Ease of use beats feature delusion.

    Just think one moment if it is really true that C# is better than JS. It was around 50/50 for years between C# and Unity JS, while BOO, as powerful as the other two, didn't play a significant role. And this was surely not because 50% of Unity users are made of morons and novices. It's the opposite. They used what did the job best for them, which is a professional approach. As already pointed out, it's not the number of pure features what makes a tool best for the job.

    Unity JS is still perfectly fine and capable to reach the goal. And it would still be perfectly fine and capable when it would be as limited as the Playmaker for example. Which it isn't. It still provides as much freedom as C#. Because the Unity API is still the same for both. And both are Mono. You can still make the very same game in Unity with both languages.
     
    ippdev likes this.
  20. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    14,300
    It has more learning resources compared to UnityScript. Yes, you can use JavaScript resources to some degree but anything you learn has to be tempered with knowledge of how to do it the way Unity actually accepts.

    Learning C# though is simply a matter of learning C#.
     
  21. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473
    That myth again. A general C# tutorial is as useful as a C++ tutorial when you want to use it in Unity: Close to zero. You can study C# tutorials for ten years, and still fail to move a cube in Unity.

    What you need is Unity tutorials. Because you work and develop in Unity. Not in a C# IDE. And there was a time when the available Unity books and the official learning projects were all made with Unity JS. Nowadays the situation is a bit different. The learning section videos now are made with C#. And the new books are getting made with C# too. But the old books and learning projects are still around. And there are still more than enough happy Unity JS users around too.

    And you haven't understood the point yet. There simply is no "best" language.

    "Better" is highly subjective and dependand of your goals. Projects needs and users are too different for that. That's why there are so many engines and languages around. And that's why there is C# and JS in Unity. You feel more comfortable with C#? Then use it! You feel more comfortable with JS? Then use it! The choice is yours! Of course just as long as there is a choice within Unity. One language is already gone.

    Sure. But why should i? My goal is not to learn C#. My goal is to develop a game. As easy and as fast as possible. That's why i use Unity at all. That's a BIG difference in what you want to achieve and do.

    Languages comes and go as fast as you switch the engine. Languages are just a tool at the road. I have happily learned and forgotten half a dozen engines and their languages over the years. All claiming that they are the best ones available. And my next engine may most probably neither use JS nor C#.
     
  22. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    14,300
    That's not a matter of the language but rather the API used to interact with the engine. Classes in C#, for example, are created identically both inside and outside of Unity. UnityScript though handles classes in an entirely different manner from JavaScript. This is because JavaScript does not actually have classes.
     
    Schneider21 likes this.
  23. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    2,886
    The OP stated he knows the basics of JavaScript. To me, that's the equivalent of saying "I understand the basics of programming" to include data types, operators, and control structures. I don't think it was incredibly out of line to recommend an alternate path that may benefit the person asking the question.

    Consider this scenario: Person A is interested in going off-roading. They indicate they went on an excursion with their friend one day in an old Jeep Wrangler, and asked for purchasing advice for getting a new Jeep Cherokee. Person B, having owned a Cherokee before, now drives a Range Rover and highly recommends it over the Cherokee.

    Could they have simply said "I bought my Cherokee from Bill's Auto Store"? Sure. But they wanted to use their experience to help someone find an alternate solution they may not have considered that would potentially benefit them.

    I'm not saying there isn't elitism with language selection in programming. But I don't think every response suggesting learning a language is trying to incite a language war, either.
     
  24. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    14,300
    What do you think Mono Develop and Visual Studio are?

    Other engines will not make use of UnityScript because it is entirely Unity's, but C# is not restricted in this manner. This binding of Mono C# for Unreal 4 is a good example, but there are also bindings for other engines such as Crytek.

    https://mono-ue.github.io/
     
    Last edited: Feb 21, 2015
  25. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473
    To me, asking a JS question is definitely not a request for starting missionary work for C#. The question was clear. Where to learn JS. Not how and why to learn C#.

    And what do you think Uniscite, Sublime Text and Notepad ++ are? Unity is the engine, the IDE (Integrated development Environment). Not Monodevelop or Visual Studio. Well, they can be used as IDE too, but in conjunction with Unity they are just the text editors.

    But Godot will not make use of C#. And neither does hundrets of other engines that uses C++ or LUA or Python or anything else instead. So yes, C# is restricted in the very same manner. C# is just of use in the cases where it is available. That's why i said the language changes as fast as you change the engine. And it's the engine that is important, not the language. You have to relearn the api with every new engine anyways.

    Well, by an unbelievable coincindence we all use Unity here at the moment, and by the same unbelievable coincindence Unity JS IS available in Unity. And for some Unity JS is simply the better choice. We've been already at the point why. There is no best language. Just user needs and available tools.

    Um, the Unreal 4 C# binding is bad example for your point by the way. Epic games has added a license clause that such language bindings has to be freely available. And Xamarin initially wanted money for it. Not sure how this one turns out. Point is, at the moment it's not of use. And also Crymono is years away from working. Version 0.4 is newest from what i know.

    I am unsure about the future of Mono anyways, now that Microsoft has made its .Net open source. Exciting times ahead.
     
  26. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,356
    With Unity 5:

    I would suggest learning C# since js is a second class citizen with all the unity sample assets being in C#. Only a very small percentage of Unity users still use js so it's kind of being phased out. If you want more help, learning C# is the best bet.

    If you want to code towards a dead end and possible eventual removal, then use js. Just know that you're not going to find much support for it going forward.

    Since it's so easy to learn C# and take advantage of it's far greater power, and it's so similar to unity js, you should just learn C# to begin with.
     
    Devil_Inside, Ryiah and Schneider21 like this.
  27. Ostwind

    Ostwind

    Joined:
    Mar 22, 2011
    Posts:
    2,771
    I don't find it bad that people suggest C# here since it seems that OP is still starting so it's still possible to change easily. Also like been said UT is focusing on C# now ie. all live sessions been only C# and new standard assets etc. done with it.
     
    hippocoder and Schneider21 like this.
  28. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,356
    I was a diehard js fan for a while - I've shipped at least 3 titles in it. But upon switching to C# I just felt like a fool. I'd rather other people avoid how I felt :)
     
    Ony likes this.
  29. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473
    I wouldn't call 20 % a very small percentage value. Given all the resistance and JS bashing here at the official board since quite a few months, and given that Unity has indeed put it onto the backseat with the learning resources just being available in C# now it's even a surprisingly high number. Which shows me that the value of Unity JS is highly underestimated.

    I'm no diehard fan of anything. I'm in fact highly pragmatic. I use what does the job best for me. And i try what works best. I switched to C#, and to me it does the job slower and more cumbersome than JS. People are simply different.

    I have no problem with people thinking that C# does the job better for them. Good luck and all the best. But i have definitely a problem with people thinking they know better than me what does the job best for me.
     
    Last edited: Feb 21, 2015
    Kiwasi likes this.
  30. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    14,300
    Exactly! Differences between the languages are minimal and most of them are lines that are hidden but implied. This can be noticed easily by analyzing the source code given on the various Unity video tutorial pages. With such minor differences, why would you pick the language with the fewest learning resources as a beginner?

    I can understand experienced programmers using UnityScript but then an experienced programmer should be capable of picking up new languages rapidly. Your first language though is rarely fast to learn. It took me a month to learn the basics of OOP, but I was able to pick up my second OOP language in days because the concepts were the same.
     
    Last edited: Feb 22, 2015
    hippocoder likes this.
  31. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,356
    @Tiles It's less than 20% and dwindling. Boo support is now unofficial. JS is next. You can stamp your feet and make a huge huff because you don't want to change a few minor things but I can't see how it's beneficial to you.
     
  32. minionnz

    minionnz

    Joined:
    Jan 29, 2013
    Posts:
    391
    I'd like to see UnityScript deprecated - but I'd also like to see real JS support added in (through an addon if required). NodeJS has proven that JS can be a great programming language with it's own style - but it'd need it's own separate API to really shine, which would be a huge amount of work.
     
  33. Nubz

    Nubz

    Joined:
    Sep 22, 2012
    Posts:
    553
    What about Bacon Script?
     
  34. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,452
    Its probably already in development as a secret language. Maybe some of us are already using it. I can neither deny nor confirm that its awesome.

    Biggest issue I see currently is that if leave code written in bacon open too long on your desktop it develops bugs. Mac users may not experience this problem.
     
    randomperson42 likes this.
  35. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473
    Hm? I did pick up C# already. That's not the problem. And migration is no problem for me anyways. As told, i have happily learned and forgotten half a dozen engines and languages over the last 15 years. Being flexible is part of the game developer job.

    Well, there is wishful thinking and there is facts.

    Wishful thinking: JS is just used by a very small fraction.
    Fact: the last official statistics tells 20%.
    Wishful thinking: JS gets deprecated soon.
    Fact: Unity 5 still supports JS, which gives us minimum two more years. Two years is a long time, and there is not a single official note about making JS deprecated. It's just some C# extremists telling us again and again that JS will be deprecated soon. The same extremists that hijacks the JS threads. BOO gots deprecated at 0,8% useage from what i remember. Unity JS is still miles away from that.
    Wishful thinking: There is no documentation anymore for Unity JS.
    Fact: Most Unity books are still written with Unity JS. There are tons of Unity JS tutorials and learning projects in the net. The learning section videos are made with C#, but the explanation underneath still contains JS. The API still contains JS. All is there. All but an official forum where you can get help with Unity JS, since the threads gets hijacked with C# praisings and wishful thinkings nowadays.

    What is left under the line is some hardcore C# extremists that tries to hijack every available JS thread to scare the JS users away and to make JS inofficially deprecated by blocking the threads. Which is plain sad, and not how it should be. Normally the moderators should stop that. And not even support it.

    What comes next? Hijack all Playmaker threads since C# is soo much betta? Hijack all Blender and Max threads since Maya is so much betta? What makes it so hard for you folks to accept that some people are simply different and let them use what they prefer?

    Stamping with the feet and huge huff? That's something for extremists. I'm a pragmatist. But i am also not easily to silence. I do have an opinion, you know.

    You overlook that i already migrated, i am already at the greener grass side. It's no academic question to me, i am not unexperienced and clueless, i will not be much happier after migration, because i already migrated and am NOT much happier.

    I could go on with C#, that's not the problem. But for me Unity JS is still the better choice. I am a unhappy C# migrant, compared to Unity JS. So when i have the choice, and the one solution works better for me, why should i be so crazy to choose the for me weaker solution? Because you told me so?
     
    Last edited: Feb 22, 2015
  36. RJ-MacReady

    RJ-MacReady

    Joined:
    Jun 14, 2013
    Posts:
    1,718
    Because C# is an actual language with an actual definition, not a hodgepodge. Just because your adjustable wrench makes a pretty good hammer and it "works better for you" doesn't mean that everybody else shouldn't train with hammers. I mean, realistically, if we're talking about a language and it becomes necessary to specify which language among different languages which are all called the same we are talking about... as in Unity Javascript vs. "regular" JavaScript... vs... ???? I think there's a tad bit of an issue there.

    I also find it curious to hear someone advocate a language which actually harms you by forcing you to a) unlearn some of what you already know just to work in one environment or b) learn things that will prove useless and wrong outside of that environment.

    <--- Check out my "unity" hammer!!!

    It's better than a regular hammer, but you just have to know how to work it.
     
    Devil_Inside likes this.
  37. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,473
    Here we are at the difference between programmer and developer again.

    A programmer is somebody who knows a language. He has a solution, his language, and searches for a problem where he can use this solution. This doesn't always end in the best solution for the problem since this way bends the problem too often towards the solution. Hey, i have spent the last ten years studying this language, i know best !!!

    A developer is somebody who has a problem. And searches for the best possible solution to solve this specific problem. At the programming front and in Unity that's for me Unity JS in most cases. For somebody else it is C#. BOTH is possible. Because people and needs are different. And i simply cannot know what requirements my next engine may have. It's of no interest anyways because i am not at the next engine, but at the current one. And here i choose what fits best. But we've also been at this point already.

    A language is no end in itself. It is a tool. And you choose your tool dependand of the job. Not the job dependand of the tool. I may never need your C# hammer. I may get better results with Unity JS. And i personally do.
     
  38. DavidDebnar

    DavidDebnar

    Joined:
    Mar 19, 2011
    Posts:
    113
    That's fundamentally untrue, false, a lie. C# both with and without Unity have the same syntax; all Unity does is provide an API in the form of libraries, hence 'using UnityEngine;' at the top. UnityScript on the other hand is heavily modified from regular JavaScript, it's actually closer to C# in terms of syntax, so techincally, reading general C# tutorials will help you move a cube in Unity, be it with UnityScript or C#.

    Now, even if I hate jumping into C# vs US arguments, C# objectively provides more features, which, obviously, you may or may not use in your final product, but they're there nonetheless. For me, I started with UnityScript and transitioned to C# about a year ago and from personal experience, things like delegates have helped me make my code a lot cleaner in certain cases. (You could argue, that broadcasting sytems are available to US as well, but they'd still be either custom or based on a C# base being called from US, although in the end it's just a matter of semantics.)
     
Thread Status:
Not open for further replies.