Search Unity

Writing right-syntax code..(JS)

Discussion in 'Editor & General Support' started by robertseadog, Aug 24, 2005.

  1. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374
    Is it ok to make your scripts in say: Textedit? This is how I have done it for most part, but now when I import unity goes crazy finding flaws in every single scripts I have! (also the included ones that you guys made).

    Usually the error is that there is a unvalid "}" or something, but it most definately should be there! (or so I think).

    When I looked in the car-race tut- you had some scripts that used if-statements, and didn't put braces ("{" and "}") to open and close the statements.. :?:

    Is there some special rule I have to look into or what? Cause according to unity most of my "}" and even some of my "=" are "not expected"..
     
  2. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    Did you make sure TextEdit is saving the files as plain text files (Format->Make Plain Text) and not as RTF documents?

    If not, try attaching one of the files that are not working to your next post, so we can take a look.
     
  3. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    We have done quite a few changes to our javascript compiler in 1.1 to make it more conform with netscapes implementation.
    So you need to use Unity 1.1 to run the racing tutorial.
    One of the changes is that it is not necessary to use the { } with an if.
    It will just assume one command to be inside the {} block.

    Try using sub etha edit. It has syntax highlighting and it works very well with unity.

    You even get compile errors updated in the background in unity when you hit save in subethaedit.
     
  4. DaveyJJ

    DaveyJJ

    Joined:
    Mar 24, 2005
    Posts:
    1,558
  5. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374
    Ok, I'll try that! And no more "{" in if statements!


    Thanks!
     
  6. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    ... well you need them if you need to execute more than one statement inside the if.

    Code (csharp):
    1.  
    2.    if( a == b )
    3.       doSomething();
    4.       print("Maybe not what you expected");
    5.  
    The above example will always run the print statement on line 3, as it is not inside the if.
     
  7. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374
    Hmm, it happens again!

    What is this?
     
  8. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    Bit hard to tell without the script file...

    If you don't want to post it to the forum, you can email it to me at keli at otee.dk