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

Scripting Madness

Discussion in 'Scripting' started by staylor, Jul 23, 2005.

  1. staylor

    staylor

    Joined:
    Jul 23, 2005
    Posts:
    4
    Ok, so I'm very new to unity and am just playing around trying to get a ship to fly around. And I can do that, but now I want to toy with controlling how the ship reacts to commands and my very simple script just doesn't work. Unity keeps giving me very odd error messages. I've writen this script in boo, javascript and c# and all fail in a different way.

    C# is the closest, but the Transform.Rotate seems to be different in C#. It's complaining that there's no overload method for Rotate that takes 4 methods (and when I don't specify Space.Self it complains that none take 3). I thought that all languages used the exact same libraries since it's all compiled to the .net cli.

    Boo just gives me the increadably meaningfull message of an error BCE0044 on line 21 at column 21: expecting "EOF", found '<DEDENT>'. Is that supposed to mean it was expecting the End Of File? Maybe my Boo script is just plain wrong? I've never used Boo before so I don't really know.

    Javascript gives the same type of error as Boo, in it's case it's line 22 at column 1: expecting EOF, found }.

    Is there maybe a code size limit in the demo version? Is my code way off, it seems right to me but of these languages I've only used c# and it seems to come closest to working.

    I'm using Unity 1.0.4 and any help would be GREATLY appreciated. Thanks in advance.
     

    Attached Files:

  2. staylor

    staylor

    Joined:
    Jul 23, 2005
    Posts:
    4
    Ok, I've figured out my problem on the c# front...the docs weren't kidding when they Rotate takes float and not double; I really should read docs more carefully :eek:

    I'm still very curious about the javascript and boo problem though, especially as boo seems like a very cool language.
     
  3. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    I took a quick look at your code. And yes, you got the C# one correct, the design of the C# language tries to avoid any implicit typecasts where you'll lose precision. Hence it will happily promote a float to a double, but cowardly refuse when you try the opposite without telling it was on purpose. :p

    Now to the boo one. I noticed that the file has a .js ending, but I assume that was not your problem, as the "else if" on line 18 should be written as "elif" in boo.

    I'm not sure about the javascript one, but I think it will work if you add braces around the else block starting on line 12, so it reads:
    Code (csharp):
    1.  
    2. ...
    3. else {
    4.    if ( tilt < 0 ) {
    5.     ...
    6.    }
    7. }
    8.  
     
  4. staylor

    staylor

    Joined:
    Jul 23, 2005
    Posts:
    4
    Ok, all three scripts work now...thank you very much.

    Two questions though, does java script and boo not support "else if" constructs? And is that just a limitation of the unity implementation, or the actual languages themselves?

    I code in c by day, some things are hard to let go (even though elif is quicker to type). :twisted:
     
  5. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    boo supports else if... it's just called elif :)

    as for javascript, the "else if" should have worked, but I think there is a bug in our implementation, that requires having braces around the statements in the if and else branches, even if it's only one statement.