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.