Search Unity

Javascript API

Discussion in 'Scripting' started by bytescruncher, Jun 25, 2007.

  1. bytescruncher

    bytescruncher

    Joined:
    Sep 12, 2006
    Posts:
    32
    Hello,
    I've seen a script in the forum about reading / writing a string to a file with javascript. The suggested method uses a StreamReader / StreamWriter. StreamReader and StreamWriter are obviously not documented in Unity manual. Where are they? Where can I find a complete reference of javascript API supported by unity? Thanks,

    Eugenio
     
  2. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,268
    You mean .NET. You can search for classes like String and Streamreader here. Here's a page with an example:

    http://msdn2.microsoft.com/en-us/library/db5x7c0d(vs.71).aspx
     
  3. bytescruncher

    bytescruncher

    Joined:
    Sep 12, 2006
    Posts:
    32
    I didn't realize that the javascript implementation in Unity is the one implemented/supported by mono. Is it? Thanks,

    Eugenio
     
  4. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,268
    The javascript may not be exactly the same, but you do have access to the entire .NET 1.1 API.

    EDIT: To look less idiotic.
     
  5. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    It is not. The JavaScript in Unity was created by us specifically for Unity.
    The reason for this is that we wanted to make sure that we optimize JavaScript for the best performance and the result is that our JavaScript is around 20x faster than other JavaScript implementations. But yes it is based on .Net thus you have the full .NET class library at your disposal.
     
  6. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Ok, there has got to be some kind of complete reference out for the aspects of scripting in Unity that are NOT covered in the manual. I had a lot of success by reading beginner's JavaScript manuals recently and asking a ton of questions on the boards. However, these are not exhaustive/immediate resources.

    The JScript section on the msdn site seems to be pretty good, but I don't know if that is the best place to gain mastery of the scripting language we can use with Unity. I just want something I can refer to that is similar to the Unity manual, in that it gives you the basic use of something and a small code example to go along with it. You can be dangerous with just a little scripting knowledge if you have access to the Unity manual, but the manual by itself can't actually get you coding anything, and the tutorials are not complete references.

    Any alternatives to msdn? Muriac suggested the following, but I don't actually have a clue what I am even looking at when I go there.

    http://www.go-mono.com/docs/

    Thanks!
     
  7. lgoss007

    lgoss007

    Joined:
    Dec 6, 2006
    Posts:
    88
    Yes and no... any JavaScript reference will do. The language itself is pretty much the same across the board with a few minor differences, which I keep track of here:
    http://www.unifycommunity.com/wiki/index.php?title=Programming_Introduction

    MSDN site is fine to use, just don't use any Microsoft specific things (which are noted on the msdn reference), and be aware of the things Unity differs on in JavaScript(that url above).

    For the Mono Docs, just click on the "Class Library" link. The class library is essentially the .NET library, though all the examples are in C#, but I like the cleanness of the Mono docs. For an example, say we want some type of collection. Go to the "System.Collections". There you'll find Lists, Stacks, Queues... lets go to the "ArrayList". There is an example, but the real good doc is at the top where it says:

    See Also: "ArrayList Members" (which is a link). When you click on the link it will take you to a list of all the constructors, methods, and properties that can be used by that object, much like the Unity docs.
     
  8. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    I bet! Where do I get one?
     
  9. lgoss007

    lgoss007

    Joined:
    Dec 6, 2006
    Posts:
    88
  10. lgoss007

    lgoss007

    Joined:
    Dec 6, 2006
    Posts:
    88
    Oh, and one more (this one is probably best):
    http://developer.mozilla.org/en/docs/JavaScript

    "Core JavaScript Reference" is nice.