Is there a way to change the "mood" using code?

Does anyone know a way to change the mood using code? As in use code to change change the scene from daylight to foggy to night. One can do this manually in the environment menu, but it would be nice to be able to do it using code to simulate passing of time in a game.


Hi Ian,

we have an internal method for this - Scene.setMood(n) where n should be a number between 0 and 1. You can use it but notice that because it’s still internal, it can be removed or changed anytime which can cause you script to break.


That worked great. Thanks Benny!

This would be a nice feature to have in blockly.

I thought I’d share a working example script (Javascript).

var mood = 0;

var dayNightChangeObject = Scene.scheduleRepeating(function(){
    mood += 1;
    if (mood > 1){mood = 0}
}, 3);

Hi Ian, nice that it worked! I took your example and created a little day-night cycle.

var mood = 0;
var speed = 0.5;

var dayNightCycle = Scene.scheduleRepeating(function() {
    mood += speed * 0.01;
    Scene.setMood((Math.sin(mood) + 1) * 0.5);
}, 0);

Thanks Benny! That cycle works great.

The Scene.setMood function doesn’t exist now.
Any other solution I can change the day night mood?

I created an example of controlling lighting. It sticks to CoBlocks and can be triggered based on time or location. Probably other stuff too but this is my rough cut.


you can do this in coblock???

It was already created using CoBlocks. You could remix the space and copy the CoBlocks to your space

Can you change the environment with coblocks???
please help me
I am participating in a programming contest and I use cospaces to program but don’t know how to change an environment. I’m from vietnames . i very like cospaces. <3

@tu_n_vi_l_a_nguy_n look at @MrWolken’s example. He achieved a similar effect using coblocks.