Cutscene like code help

alright, so I’m making a cutscene of text (no extensions just splash dialog and then a function), so I have an onUpdate(function() {} and I said this:

game.onUpdate(function() {
if (speed > 20) {
game.splash(“blah”)
game.splash(“blah”)
game.splash(“blah”)
Hard()
}

(you can copy and paste that into javascript, and convert it to blocks if needed)

I understand the problem here, it’s running this code every time it updates and the code sees that the speed is over 20. Making the code basically run forever, because it doesn’t update on intervals or stop updating, it always updates. Is there any way to fix this?

JAVASCRIPT HELP!

By the way ‘Hard()’ is a function that has a game.onUpdateInterval(0000, function() {} inside of it if that helps. The code inside of this function does not have any interference with any other code in the project.

The easiest way to handle this would be with a boolean flag; you keep track of whether you’ve shown the cutscene before in a variable, and only show it the first time it triggers. For example, something like:

let hardModeSceneDisplayed = false;
game.onUpdate(function() {
    if (speed > 20 && !hardModeSceneDisplayed) {
        hardModeSceneDisplayed = true;
        game.splash(“blah”)
        game.splash(“blah”)
        game.splash(“blah”)
        Hard()
    }
});
1 Like

Thanks!