Feedback Execute multiple events in one script

Discussion in 'GameMaker Studio 2 Community Tech Support' started by Kapser, Apr 4, 2019.

  1. Kapser

    Kapser Member

    Joined:
    Nov 23, 2016
    Posts:
    8
    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.

    Thanks!
     
  2. YellowAfterlife

    YellowAfterlife ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    2,404
    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
     
    Kapser likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice