• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

 Execute multiple events in one script


One of the few things GML doesn't have over other languages is the ability to write multiple events in one script, which would make it so much easier to write modulable scripts.

Example : I am writing a playerAttack script, which includes the create event, step event, a animation end, an alarm, etc.
If i had dozens of those script, it would be much easier to have all their codes grouped together, and if I wanted to edit that particular feature, i wouldn't have to navigate through multiple place, or in my case generally ending up making a scrPlayerAttackStep, scrPlayerAttackCreate, etc..
I don't know how it would work for the order of execution but I am guessing it is nothing impossible to do.



ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
A common pattern would be to have the script take what it's supposed to do (initialize, update, draw, etc.) as an argument. Other option is to use event_type+event_number to detect the event that a script is called from and decided accordingly.

Ability to define multiple functions per script is on the considerations list (if the stars align, could land late this year together with "GML improvements") https://help.yoyogames.com/hc/en-us/articles/360022211472