Event Trigger

Note: See release notes below:

This plugin allows a pseudo event system to be utilized in a Construct 3 project. What this means is that you can have an event generated, along with a message to pass along, and you have can one or more events listening for this event and perform different tasks.

This gives you the ability to essentially create a publish and listen structure to create a little better encapsulation in your projects.

To see how to use this, please look at the included sample project. That shows how to have an included event sheet generate an event, but the multiple parent event sheets respond differently to the event. You could also listen for the event in more than one loaded event sheet and perform different actions.

Tips

  1. On an event sheet that is going to listen for an event you must make sure that the listening event sheet is included directly or indirectly to the current layout. This is normal for how triggers work in general.
  2. Capitalization matters, whatever capitalization is used to send an event, the listeners must match to catch the event. Note: I may change this in a future version.

Release Notes

Version 1.3.0

Major rewrite of the internals of this plugin. The plugin is now very performant for larger projects, does not rely on the tick event anymore, and takes advantage of how triggers work to perform very efficiently.

Version 1.2.0

You now have the ability to add multiple items to the message that gets sent and picked up by a handler.

  1. In order to support backward compatibility, the expression LastEventMessage has been deprecated, but if it's your project already it will only return the first message item.
  2. Going foward you will need to use the expression GetEventMessageAt(index), where index is the zero based index of the message item you want to look at.
  3. A new expression called GetEventMessageItemCount has been added to get a count of the number of items in a message.
  4. If you try an access an index that doesn't exist, you will just get an empty string back

The included example has been modified and will only work with this version going forward.

Download

1.3.0 Stable (49.99 KB)

Info

  • Deprecated addon Deprecated
  • License MIT License
  • Copyright Robert Greenberg. All rights reserved.

Statistics

  • Download count 297 total downloads
  • Latest download count 254 downloads of latest version
  • Average download count 1 downloads per day average

Owners

  • 14 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • Tried it out in the last Ludum Dare! Liked it a lot, it's a nice way to order code :) My entry with source code is over here: alcex.itch.io/tetromino-ghost-smasher

  • What's different from function?

    • Actually typing the response to your question made me think through a scenario that made me realize that there is a bug in the code. If you only send one event, but there are multiple handlers waiting to respond, only one will trigger. I am working on that and will issue a new version soon.

    • That's a great question.

      1) It decouples your code so you fire off an event and aren't concerned who or if anyone handles it.

      2) Based on the event sent, you could have different logic executed on different event sheets. So lets say you have a player being hit by bullets. The player event sheet sends an event player hit, It's responsibility is all things about the player. The title screen may act on that message by changing the color of player. On the game screen it may decrease the health of the player.

      3) You also could have multiple items respond differently based on the event. Lets say you emit an event for player health low. You could have a health bar that listens for that event and changes color, the player could listen for that event and start flashing, etc.

      So it's a different way of organizing and thinking about your code in a more event system driven way where one event could have a multitude of results.

      Hope this helps

      • Doesn't this work with only the Function object?

        Call the Function "Screen Touch" (from your blog post), and in this function call other functions or other code

        Load more comments (5 replies)
      • Ok, I kind of understand now:

        1.It's for keeping code split and orgnazied. I do have player code in enemy event sheet.

        2.It's a broadcast and there is no broadcast for function plugin.

        One thinking : Compare to function, this event have only 1 parameter, it has more work to do if I want to picking object with messages.

        Load more comments (2 replies)