Weather cycle script

I have a script that (in theory) will choose a random number (1 to 4) and enable the weather condition corresponding to the number, disable the entity and enable the next random weather condition.
here is the script. Please let me know what I should add, or let me know of any errors and please help me make this script better.

var WeatherCycle = pc.createScript('weatherCycle');

// initialize code called once per entity
WeatherCycle.prototype.initialize = function() {
    // Set the interval for generating a new weather event (in seconds)
    this.interval = 2;
    // Set the time of the last weather event
    this.lastEventTime = 0;

// update code called every frame
WeatherCycle.prototype.update = function(dt) {
    // Check if it's time to generate a new weather event
    if (this.lastEventTime + this.interval < {
        // Generate a random number between 1 and 4
        var event = Math.floor(Math.random() * 4) + 1;
        // Find the corresponding weather entity in the scene
        var entity = + '_weather');
        // Enable the weather entity
        entity.enabled = true;
        // Update the time of the last weather event
        this.lastEventTime =;
}; is a function, so it should be

1 Like