How do you create and use custom events?

0 favourites
  • 3 posts
From the Asset Store
Very simple code without excess options (15 events for server and 11 events for client)
  • Hello. I want a way to create, dispatch, and listen to events I create myself through scripting. I've seen from the IBehaviorInstance API docs (cf. image) that this seems to be possible with the C3.Event constructor. However, I can't find the docs for the C3.Event constructor or even for the C3 API itself. Could someone provide me with the link for the docs so I can learn about it (or maybe just tell how to create, dispatch, and listen to custom events using this C3.Event)?

    Tagged:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It already tells you everything you need to know in that paragraph - the constructor parameters are eventName and isCancellable. That's all there is to it.

  • I had made a video where I go over one of the use cases for this in a game I am working on. https://www.youtube.com/watch?v=MEQtDCqeDu4&t=43s&ab_channel=Piranha305

    the video is quite long but, in a nutshell, I had a color picker system that was used on multiple layouts and when a new color was selected, I would create and dispatch a color-changed event (I would attach the hex value to the event data)

    I did run into a few issues removing events, and getting unintentional duplicate events, so I created a manager class to ensure events would not be duplicated and cause issues and also to keep a function reference used to remove events.

    But to consume the events you just need to call addEventListener on the instance.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)