I need to get a reference to the device I am subscribing an event to so I can know what devices are calling the event when they are activated by the player, but currently, I am at a loss, maybe just burned out.
Basically, I need to subscribe to multiple color-changing tiles OnActivated event, and when one gets activated, I need to know which does so I can run some number magic based on that tile.
If anyone can give me some pointers on how to do it, my brain is fried at the moment.
You’ll have to capture the device instance yourself when subscribing to the event. Here is one way you can do that using the concurrency primitives
OnBegin()<suspends>:void =
for (Device : MyColorChangingTileDevices):
# Spawn a new task for each device. Internally this function is going to suspend until the ActivatedEvent happens.
spawn { WaitForActivation(Device) }
WaitForActivation(Device:color_changing_tiles_device)<suspends>:void =
# Suspend this call
Device.ActivatedEvent.Await()
# Logic that happens when the ActivatedEvent runs
# You still have the device instance in this function, which you can use to run your magic numbers
At first, I used @Incredulous_Hulk way but ended up pivoting to something more alike this approach.
I created a new class and subscribed to a function in that class. In the construction of the new class, it received the color-changing tile class that it’s subscribed to, and any other expressions from the original class needed to run the magic numbers.
Huge win. Thank everybody, I’m marking this as the solution because it solved my problem in the best way.