LINK event - use a variable to set link to external event

This is something that I use very often in game maker in order to create a state machine. What you do is create two external events:
-state1
-state2

Then you control which one of the two is being run by using a string variable to run an external layout

here is an example

The idea is that by calling an external event via a string variable, you can run only one of a number of different external events. They you can store a state of your player or your enemy in an external event and have one external event per state.

Have been thinking about this too until by chance if found out that you can place thouse “special” events (like link / code etc.) in a sub event which enables one to place the corresponding conditions in the parent event.

But in that case you would then have to create a condition for every possible string variable and use many many lines of logic.
Where as if you do it the game maker way - the method that I am proposing - you need only one line of code and the event sheet is being called simply by naming your string variable the way the event sheet is named. :mrgreen:
You have a string variable called “STATE” and in it you put the state of your enemy AI or character or whatnot. So if they are chasing the player, you put the “chase player” string in the “STATE” variable, which then automatically executes the “chase player” event sheet, instead of the “idle” event sheet that it has been running. In that way the active event sheet is a single variable and the programmer does not need to put many conditions. It’s all automated by better design and less logic writing.

Didnt that just blow your mind? Even construct2 doesnt have it. But game maker does. I think it’s one of the most brilliant aspects of their engine’s design. The way you can create functions and structure your code is superb. It allows for very good code reusal!

I realized that this can also be done with functions:
scirra.com/tutorials/1063/h … -callbacks

Unfortunatelly not possible to do for html5 games in gdevelop yet. But html5 functions are on the trello board. I will test this callback approach in gdevelop native later. :stuck_out_tongue:

I’ve finally found the topic explaining why it is not possible (I was sure I had read it somewhere): [url]Extend functionality - #3 by Lizard-13]