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.

4 Likes

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.

4 Likes

That worked great. Thanks Benny!

This would be a nice feature to have in blockly.

1 Like

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

var mood = 0;
Scene.setMood(mood);

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

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);
3 Likes

Thanks Benny! That cycle works great.

1 Like

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

1 Like

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.

5 Likes

you can do this in coblock???

1 Like

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

1 Like

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

1 Like

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

1 Like