Wrapping Subscribe To Pass Additional Data
1448,621 Views
-
#usage example (when subscribing to an event that returns an agent) ButtonDevice.InteractedWithEvent.SubscribeAgent(OnButtonInteract, "Hello!") OnButtonInteract(Agent : agent, Text : string) : void = Print("Button interacted with {Text}!") #usage example (when subscribing to an event that returns tuple(), aka an empty tuple) CampfireDevice.CampfirePulseEvent.SubscribeEmpty(OnCampfirePulse, 90210) OnCampfirePulse(Number : int) : void = Print("Campfire pulse had {Number}!") #The important code is below. Put this in one of your verse files, perhaps utils.verse or something! using { /Verse.org/Simulation } (Listenable : listenable(agent)).SubscribeAgent(OutputFunc : tuple(agent, t)->void, ExtraData : t where t:type) : cancelable = Wrapper := wrapper_agent(t){ExtraData := ExtraData, OutputFunc := OutputFunc} Listenable.Subscribe(Wrapper.InputFunc)
You're reading a preview
The full reference is free for BrainDeadGuild Discord members — sign in to read it all, or open the original at the source.
Sign in with your BrainDead.TV / BrainDeadGuild Discord account for full access.