[JS]runtimeScene is undefined in external JS file

First of all, sorry for the noob questions, I’m really trying to figure things out on my own using the GDJS documentation and other JS tutorials I’m even trying to use the source code on github but this time I can’t find the solution.

So what I’m trying to do this time, is to use an external JS file to store functions, so during development I can use simple and short functions in JS events whenever I need it.

this is the code I have trouble with:

//check if mouse button is pressed function mouseButtonDown(mButton){ var mbDown = runtimeScene.getGame().getInputManager().isMouseButtonPressed(mButton) return mbDown }

When I put this code in to a JS event, it does works, but when I put it in to an external JS file, and include the JS file in my project I get the famous runtimeScene is undefined error message. I have tried to use gdjs.runtimeScene, but in that case I get ‘unable to get property getGame() of undefined or null reference’

So really, at this point I have no clue what am I doing and what am I supposed to do :frowning:
example.zip (3.23 KB)

Any help would be great :slight_smile:

If you put your function outside, you should add a parameter to be able to pass runtimeScene to it.

I never thought I can do that.
Thank you :slight_smile: