I have a class where I store triggers inside an array. But since it’s a class, I need a way for the creative_device to know when any of those devices has been triggered so it can start a function.
How can I do that?
Thanks a lot!
using { /Verse.org/Simulation }
using { /Fortnite.com/Devices }
using { /UnrealEngine.com/Temporary/Diagnostics }
triggers := class<concrete>():
@editable var Trigger1 : trigger_device = trigger_device{}
@editable var Trigger2 : trigger_device = trigger_device{}
@editable var Trigger3 : trigger_device = trigger_device{}
main_device := class(creative_device):
@editable var AllTriggers : []triggers = array{}
Trigger1Triggered(Agent:agent):void=
Print("Trigger 1 may have been triggered idk")
#This function should be enabled whenever trigger 1 is triggered.
in raw Unreal this would be a delegate (probably a multicast Delegate)
one way you can go about this is if all of the receiving objects have the same interface or parent class then you can use a manager type system where the receivers would register to the manager, which puts them into an array, and then when the time to broadcast happens if the array is not empty you iterate over the array, and if the object is still valid call the receiving function.
delegates would get around needing to know the objects type because it using purely argument matching. (again this is with raw Unreal)
I didn’t quite get it, I’m still a bit of a beginner with Verse and don’t fully understand everything yet. Could you give an example of how you would solve it using the code I provided in the post? Thanks!