Javascript: At the beginning of the scene

it seems to be a simple question but I haven’t found it in the documentation.
So, how do I react to the “At the beginning of the scene” event in Javascript?

1 Like

Here the documentation for the function;


The function check if it’s the first frame, so the JSevent have to be called at each frame, not in a subevent.

So I guess you have to code:

if( gdjs.evtTools.runtimeScene.sceneJustBegins() ){
 // add more code here

1 Like

Thanks for that hint! I’ve overseen the function sceneJustBegins(). Using isFristFrame() works fine like this:

    // Do the magic

The example with gdjs.evtTools.runtimeScene.sceneJustBegins() leads to an Error (Uncaught TypeError: Cannot read property 'getTimeManager' of undefined) ¯\_ (ツ)_/¯

1 Like

That is kinda obviously you take a look at the docs or bouge screenshot from the implementation, since that call is not passing in runtime scene as an argument, even though this is a wrapper function calling methods on it.

Not really, any code used in gdjs.evtTools are functional wrapper functions for the JavaScript API to be called by the events code generator. You should use the JavaScript API directly when working in JavaScript whenever possible, not those wrappers.