A downloadable asset pack

Download NowName your own price

[INFORMATION]

This is a Pub/Sub implementation for GMS2.3+

  • Did you ever need to send messages between instances?
  • Do you need your weather system to send a message to your entities saying it started raining?
  • Do you need your player to publish actions that will be handle by another managing system? (ie.: achievements)

[QUICK GUIDE]

1) You need to instantiate a Publisher, using the following code:

publisher = new Publisher();
   
publisher.registerChannel("test"); // registers a communication channel

2) Subscribe to a channel within that publisher...

testCallback = function(_params) { show_debug_message(_params) }
   
subscription = publisher.subscribe("test", testCallback, false);

3) Finally you can publish to that channel with a custom parameter and all subscribers will receive that message

publisher.publish("test", "Say hello world!!");

4) When you need to remove a subscription you can rely on the weak reference system that will automatically remove subscription to dead instances/structs OR if GMS2 GC doesn't kick in just cancel the subscription manually using:

subscription.cancel();
   
// OR
   
publisher.unsubscribe(subscription);

NOTE: manual subscription removal is more reliable


[USAGE]
This library provides a set of useful function that you can use to send messages through channels however you want.

publisher = new Publisher();
      
// Registers a new communication channel
publisher.registerChannel(channel)
    
// Publishes a message (params) to a channel (triggers all subs)
publisher.publish(channel, params)
   
// Subscribes to a channel with a callback method
subscription = publisher.subscribe(channel, callback, releaseRef)
   
// Removes a given subscription.
publisher.unsubscribe(subscription)
      
// Removes all subscriptions to a channel
publisher.clearChannel(channel)

The subscription instance itself provides a set of utility functions that can be used to manipulate the event after it was scheduled:

subscription.cancel() // Cancels the current subscription.


[NOTES]

The demo project serves as an example for the Publisher system and all its code is inside the Demo folder of the asset pack. You don't need to include it to use the asset.


[COMPATIBILITY]

The asset is fully compatible with 2.3+ and is purely written in GML making it compatible with all exports available.

Download

Download NowName your own price

Click download now to get access to the following files:

xPublisher.yymps 12 kB

Leave a comment

Log in with itch.io to leave a comment.