x


Public Class Error

I'm working on this script to make a day and night time system for our game. The problem is I get these errors in Unity's console "Assets/TimeOfDay.js(38,1): BCE0043: Unexpected token: public. " "Assets/TimeOfDay.js(38,18): BCE0043: Unexpected token: (. "

after each of my classes. Also I wanted to know what the best program is to edit scripts with . I tried setting Eclipse up with Unity but I got errors every time i coded with it. Also there was no syntex highlighting for Untitys JavaScript.

why does this site keep taking my classes out of the code?

/////////////////////////////////////////////////////////////////////////////
///
///     This script will get time and set light status to day or night
///         By Jared .S Chase 
///                 1/14/2011
///
/////////////////////////////////////////////////////////////////////////////

function Update () 
{
    var timeAccelerator = 3.0; // for now this is set to 3 until we extract user input from the settings / config menu 
    var gameTime = Time.Time;  // Time.Time returns time since you started playing. 
    var acceleratedTime = gameTime * timeAccelerator;   

    if( acceleratedTime <= 4 ) 
    {
        Dawn() ; // set dawn class for time and height settings
    }else if( acceleratedTime > 4 && acceleratedTime < 8 ) 
    {
        Morning(); // set morning class for time and light settings 
    }else if ( acceleratedTime > 8 && acceleratedTime < 12 ) 
    {
        Noon(); // set morning class for time and light settings 
    }else if ( acceleratedTime > 12 && acceleratedTime < 16 )
    {
        AfterNoon(); // set the after noon class for time  and height
    }else if ( acceleratedTime > 16 && acceleratedTime < 20 )
    {
        Evening(); // set the Evening class for time and hieght 
    }else if ( acceleratedTime > 20 && acceleratedTime <= 24 )
    {
        Night();  // set the Night class for time and height 
    }
} 

// Create our classes for each time of day 

public class Dawn()
{
}

public class Morning()
{
}

public class Noon()
{
}

public class AfterNoon()
{
}

public class Evening()
{
}

public class Night()
{
}
more ▼

asked Jan 15 '11 at 01:34 PM

jchase520 gravatar image

jchase520
19 4 4 10

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You don't seem to be using your classes correctly. You don't just call Dawn(). Dawn is a class, not a method and you aren't doing anything by just saying Dawn() so nothing will happen when you say that.

It looks like you actually want to use functions instead:

function Dawn () {
     //Change your lighting and stuff.
}

or you could use an enum and a switch statement.

more ▼

answered Jan 15 '11 at 02:03 PM

Peter G gravatar image

Peter G
15.1k 16 44 137

yea right now the classes are empty till the animator gives me the tag names of the items that will be edited. in the meantime im setting up the frame work .

why would I want to use a function instead of a class?

yea this is my first time using JavaScript , normally I'm a Java / Pawn programmer .

Jan 15 '11 at 02:06 PM jchase520

and I would have used a switch statement instead of so many if else's but i don't think you can with multiple conditions in the switch parameters in JavaScript can you?

Jan 15 '11 at 02:09 PM jchase520

If your a java programmer, then you should use C#, it will feel much more familiar to you. You would use a function because your current syntax is not correct, js will think what you are currently doing in the if statements is a method call, and that is probably why it is confused that you are defining it as a class further down.

Jan 15 '11 at 02:19 PM Peter G

wouldn't it be better to just use the class syntex correctly?

Jan 15 '11 at 02:21 PM jchase520

I don't know how you are setting up your frameworks, but if you just want to change a few settings, a method makes more sense to me because you can just call it once and be done with it.

Jan 15 '11 at 02:22 PM Peter G
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5275
x3570
x2031
x352
x182

asked: Jan 15 '11 at 01:34 PM

Seen: 1408 times

Last Updated: Jan 15 '11 at 01:54 PM