How to use JavaScript

Hello.
I want a script to be applied when a button is pressed.
Is it correct to put the javascript under a condition, like a capture image?

Yes, in your situation, you can use it as a subevent.

The Javascript event is just like any event. If it’s all the way to the left it will run on every frame. If it’s a subevent, it will only be triggered when all of the previous conditions are true.

1 Like

It’s recommended to put JS code in extensions instead of directly in the main events to keep things tidy.
https://wiki.gdevelop.io/gdevelop5/events/js-code/javascript-in-extensions/

2 Likes