[SOLVED] A way to write "global code" true for all scenes?

Hey guys, I recently got into GDevelop and it is awesome. In just one week I already spent around 30 hours on my first game :slight_smile:

So far I was able to sort out everything with the forum or other resources, but there is one thing I was not able to figure out (to my surprise, cause it seems so basic).

The question is: Is there some sort of way to write code that is not specific to a scene – but globally true, for all scenes? For example, the music in my game can be muted with the release of the V key. I want this to work in every scene. As of now, I copied the same few lines of code blocks into all of my few existing scenes, but there must be a better solution.

Thanks guys!

Hi @Languste, welcome to the forum.

Each scene runs it’s own events, and there is no such thing as “global code”.

What you can do is copy the code into an external event, and add a link to that external event in your scenes (instead of adding the whole code). So any change made to the code is automatically updated in all the scenes.

Create external event:
https://wiki.gdevelop.io/gdevelop5/interface/events-editor/external-events/

Link external event:
https://wiki.gdevelop.io/gdevelop5/events/link/

2 Likes

Thank you for this quick answer! I will try using these “external events” later today. If you don’t hear from me anymore, it worked :stuck_out_tongue: But at first glance it seems like exactly what I was looking for! Just like I assumed, what I wanted is possible – I simply did not find it via search because I was searching for something like “global code”. Have a good day!

1 Like

No problem and good luck with your game! Good day to you as well :slight_smile:

1 Like