Event System 2: Coding & Framework | GMS2

Поділитися
Вставка
  • Опубліковано 19 гру 2024

КОМЕНТАРІ • 59

  • @FriendlyCosmonaut
    @FriendlyCosmonaut  6 років тому +21

    Another way to fix our problem of immediately unregistering when an event script gets called is - instead of using a loop that increments to run the listener scripts, we could use a "reverse loop" (we start from the end and work our way to the start)! This means the order of our list won't mess things up for entries "downstream" when they get removed. We also wouldn't have to go to the bother of putting "return true" in certain scripts - we would just put event_unregister as normal. Thank you to xDGameStudios for pointing this out!

    • @homunculus1984
      @homunculus1984 5 років тому +3

      This works as long as instances remove only themselves form the list, but if one of your event callbacks removes another instance that has yet to be processed, you run into the same issue. I solved this in a project by using a temporary copy of the listeners list just for the loop. You do have to check for the existence of the instance running the event beforehand in this setup, but it's something I'd recommend anyways just as a safety net (if for some reason you forget to call unsubscribe somewhere).

    • @fierorecensione5828
      @fierorecensione5828 Рік тому

      In event.rainStarts i think there is a switch or something like that somewhere to trigger the rain function.
      How is it work the event_fire() and the event_unregister()?

  • @thedanish5523
    @thedanish5523 11 місяців тому +2

    5 years later, still an excellent system. Made a few updates with some of the nice new features GMS2 has, and it works wonderfully for my RPG project!

  • @AvengingCondor
    @AvengingCondor 4 роки тому +5

    This video was supremely helpful with my current project, thanks for putting out such great videos!
    For anyone who may be having a similar issue, I encountered a problem with this system where I had an event listener tied to an instance that I needed to remain active rather than unregistering once it triggers, as the event handled toggling something on and off. However, because I restarted the room when the player died and the event handler was persistent, it would register a duplicate event listener every time the room restarted and cause the event to trigger multiple times for the same listener.
    To resolve this, I added an extra check to the event registry script to iterate through the listenerList(if one already existed for the given event) to see if the object ID matches any already in the list. If a match is found, the rest of the script is skipped over and the listener isn't added to the list.

    • @fierorecensione5828
      @fierorecensione5828 Рік тому

      In event.rainStarts i think there is a switch or something like that somewhere to trigger the rain function.
      How is it work the event_fire() and the event_unregister()?

  • @calebtaylor3760
    @calebtaylor3760 5 років тому +5

    I would like to let you know that I have been studying and learning a lot of Game Maker Language on my own and all of the videos I watch by you are all of amazing quality. I frequent many different UA-cam channels on all similar topics and as I keep watching more and more tutorials I keep ending up learning from your videos the most. I really appreciate what you do and just want to make sure you know you are appreciated. :)

  • @chicohaze
    @chicohaze 4 роки тому

    This is just what I was looking for. Thanks so much for posting this. I ended up putting my arguments into their own array like this: listenerInfo = [listener1, script, [arg1, arg2]] , and I used the "reverse loop" like you suggested. Those were the only changes I made. Great video.

  • @Sammenator
    @Sammenator 6 років тому +1

    This definitely is the most elegant system I have come across in gamemaker so far, great video!

  • @homunculus1984
    @homunculus1984 5 років тому

    Great tutorial, definitely needed! I implemented something similar (which by the way is essentially the observer pattern) for my inventory system, so that adding / removing from the inventory causes an event to be fired, decoupling the inventory data from its representation, and provides an easy way for the player to react based on the equipped items.

  • @mallen1846
    @mallen1846 6 років тому +1

    One of the best gamemaker developer content creators out there. Keep up the excellent work it is very much appreciated.

  • @pwndpp
    @pwndpp 6 років тому +1

    I just wanted to give feedback to you, as you helped so much with this tutorial. I immediately implemented the system in my project and must say that it is soooooo useful. Thank you for your time. Be awesome, and can't wait for more tutorials from you.

    • @fierorecensione5828
      @fierorecensione5828 Рік тому

      In event.rainStarts i think there is a switch or something like that somewhere to trigger the rain function.
      How is it work the event_fire() and the event_unregister()?

  • @ksioncdesign7075
    @ksioncdesign7075 6 років тому +1

    You make the best tutorials on YT. You are great teacher.
    PS Sorry for my poor english.

  • @sixiangyang
    @sixiangyang 6 років тому +4

    Thanks for updating ,cosmonaut ,long time no see!!!welcome back.

  • @MaxIgnatiev-lg5xx
    @MaxIgnatiev-lg5xx 6 років тому +1

    I look forward to the next part! Your Game Maker tutorials are the best on UA-cam))

  • @nuclearbeeberman
    @nuclearbeeberman 5 років тому +5

    Really like the tutorial but would also love to see another one that explains everything a little bit more with more examples.

  • @sweetblackguns
    @sweetblackguns 6 років тому

    Thank you for your hard work. Your videos are so clear and informative.

  • @Kazumo
    @Kazumo 6 років тому

    This is lovely! Thank you so much for your tutorials. I absolutely love them and they are incredible! Please keep up the amazing work!

  • @StuffToons
    @StuffToons 6 років тому +4

    Thanks!! I was waiting for this. Keep up the good work 🤩!

  • @Kyt2024
    @Kyt2024 6 років тому +1

    This is a fantastic tutorial. Thanks a bunch!

  • @LXZ
    @LXZ 5 років тому +1

    I may suffer from too little sleep but I currently don't understand how to implement this. Do you plan on any follow ups explaining how to write scripts for this system?

    • @LXZ
      @LXZ 5 років тому

      Okay, nevermind. It likely was the lack of sleep ;)

  • @sylentdoom
    @sylentdoom 6 років тому

    You're a genius coder.

  • @brianjarema264
    @brianjarema264 4 роки тому +3

    if you dont understand how this is working here is a short comment I wrote for the code you can place in the event manager in case you forget.
    //event_register_script(event.rainStarts,id,script) this code adds its self as a listener and fires its code when that event_fires().
    To fire an event and cause all listeners to react by running their scripts simply call
    event_fire(event) where the event is a named event in the enum below.
    example of the data structure created
    keys Values
    rainStarts [
    [listener1"obj", script"genaric or unquie function"]
    [listener2"obj", script"^"]
    ]
    to unregister return true after listener excutes its script. ie ive taken my umbrella out dont take it out agian.
    you can always regester as a listener to event agian once its applicple.
    */
    the reason I suggest adding this to your eventManager obj if you don't understand is that a quick look from the data structure and the enum should tell you what you need to do next inorder to have this code work for you.
    Thank you very much FriendlyCosmonaut

    • @fierorecensione5828
      @fierorecensione5828 Рік тому

      In event.rainStarts i think there is a switch or something like that somewhere to trigger the rain function.
      How is it work the event_fire() and the event_unregister()?

  • @jp3d911
    @jp3d911 6 років тому

    hoooo yeah ...I was waiting for this one ! thanks a lot ... I really like the way you go in depth ! keep it up !

  • @FerdinandCoding
    @FerdinandCoding 5 років тому +3

    how do the npc's know when the rain starts so they can pull out their umbrella
    edit: would I use the event_fire script, and also when would i use the event_unregister script

    • @rpgtogether7022
      @rpgtogether7022 5 років тому

      In the object where rain starts: fire rain start..
      PS: Don't forget to register

  • @ulone5656
    @ulone5656 6 років тому +2

    Cosmonaut can you help me understanding shader?, i kinda having a hard time understanding it

  • @fierorecensione5828
    @fierorecensione5828 Рік тому

    In event.rainStarts i think there is a switch or something like that somewhere to trigger the rain function.
    How is it work the event_fire() and the event_unregister()?

  • @xotmatrix
    @xotmatrix 6 років тому

    Useful and well presented. Thanks!

  • @blinnell
    @blinnell 6 років тому

    Love your videos. Keep up the great work.

  • @rpgtogether7022
    @rpgtogether7022 5 років тому +1

    Hey! I encountered a problem in the event_register where it says that the line ds_list_add(listenerList, listenerInfo) the argument takes a number. Which also makes me question DOES THIS FUNCTION ADDS AN ARRAY?
    EDIT: I fixed it I forgot the logical not in line number 11..

  • @DuckieOnQuack
    @DuckieOnQuack 6 років тому

    @FriendlyCosmonaut do you think you could make a video about the hoverboard mechanics you had in the demo?

  • @shadowSquall1
    @shadowSquall1 4 роки тому

    Can anyone clarify what the Rain Starts and Rain Ends listed in the numerator are? Are they objects? Scripts? I don't follow how those 2 data points in the "Events" enumerator helps you use Event_fire script. Any clarification would be greatly appreciated. I'm clearly missing how it all comes together.

    • @brianjarema264
      @brianjarema264 4 роки тому +1

      they are the keys/the names of your events that you are registering your objs as "listeners" too in order to run their scripts when the enum value is called.
      so event_register_script(event.Rain_Starts,id,itsRaining()); when put into your creation code of an obj should register it as a listener to that enum
      and when event_fire(event.Rain_Starts); is called the listeners register to that should run their subsequent scripts.

    • @shadowSquall1
      @shadowSquall1 4 роки тому +1

      @@brianjarema264 Thank you! I will take another look at it

  • @DYLwat100
    @DYLwat100 6 років тому

    This deserves more views

  • @brianjarema264
    @brianjarema264 4 роки тому

    I am having a weird problem where I can't get my system to register any new scripts I have created. that is I have an event.one, event.two and script_one and script_two I can have as many new events but I can not create any new scripts and have them work as register. naming conventions do not matter nor do create a new event manager. in fact, a separate event manager exacerbates this problem. Has anyone had trouble registering more than two scripts?

  • @Slouid
    @Slouid 6 років тому

    Hey what a great video! Just wanted to let you know that your patreon link in the description isn't working.

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  6 років тому

      Oh whoops, thank you! I fixed the description now haha.

  • @KoniWorx
    @KoniWorx 3 роки тому

    I have a really hard time visualizing this in my head so I mostly copy pasted what I saw. I think stuff like this could really use some visuals.

  • @dayf722
    @dayf722 6 років тому

    THIS IS SO HELPFUL

  • @cesurbasoglu4144
    @cesurbasoglu4144 6 років тому

    This looks very similar to your cutscene tutorial!

  • @Dimbark
    @Dimbark 2 роки тому

    you use script_execute a lot in your videos, but that almost always costs a lot of processing power. when I optimize my games, oftentimes script_execute is first to go

  • @jackdavies1960
    @jackdavies1960 5 років тому

    Hi FriendlyCosmonaut! Hope you're well.
    tl;dr: I need help with registering 'events' from the 'enum(event){1,2...}' into the ds_map
    I'm a huge fan, and your videos help me so much for anything concerning GameMaker. I have so many positive things to say about you, from the amount of helpful/tutorial content you produce and its quality, to your own creations -- especially the devlogs about Project Magenta and your relationships/comradery with your sister!
    Anyway, the million potential compliments aside, I am struggling a bit on understanding this event system.
    I've everything as you've shown in the video, but I'm having trouble understanding how to say to these lists and scripts that "This object is a listener" and "this listener wants to perform this script"
    As I have it, I have an obj_demo with a demo_script, which just changes its sprite_index to a different coloured one.
    I have in my obj_demo's instance creation code:
    event_register_script(event.demoEvent, id, demo_script);
    I think what I'm struggling to understand is how the enumerator is actually used to tell the eventmanager to add that event into the map?
    I would appreciate it so much if you could try to explain where I'm going wrong, but I will endeavour to solve it on my own! Thanks so much for all of your videos, keep them up, you're very very talented! :D

    • @rpgtogether7022
      @rpgtogether7022 5 років тому +1

      EDIT: Use event_fire

    • @shadowSquall1
      @shadowSquall1 4 роки тому

      I know this was a while ago, but did you ever figure this out?

    • @shadowSquall1
      @shadowSquall1 4 роки тому

      @@rpgtogether7022 I know this was a year ago, and is a long shot, but what type of code is the "Event" that's listed in the event_fire script? In FC's example in it's listed as Rain Starts & Rain Ends. Are those 2 events in the event_manager object enumator objects? scripts? And where do you put Event_register?

  • @azeriustv
    @azeriustv 5 років тому +1

    OMg i think im going back to Rpg Maker 2000

  • @CarlBergsdorf
    @CarlBergsdorf 6 років тому +1

    Coding your own games is easier than you think.

  • @fierorecensione5828
    @fierorecensione5828 Рік тому

    top video!

  • @svdcg
    @svdcg 6 років тому

    Delightful voice. More lessons please)
    P.S. From Russia with love.

  • @TheShirsh
    @TheShirsh 6 років тому

    Thank you!

  • @theask6830
    @theask6830 4 роки тому

    I like this

  • @lksxxtodin5292
    @lksxxtodin5292 Рік тому

    thanks!

  • @bovery23
    @bovery23 6 років тому +1

    There are levels to this coding game....too high for me lol