#16. Context Variables - Callbacks

6 messages · Page 1 of 1 (latest)

midnight walrus
#

If you've read the post about [Furni/User references](#1241007337704001547 message), you know that we can save furni/users in variables.

For context variables this opens up a brand new possibility: callbacks! This can be easily created by storing the @id of an Antenna inside a context variable, and then sending a signal to the antennas with the specified @id

#

I've created this small Wired setup that I'd like to reuse in a lot of places.

When the antenna activates, it will find all the BC blocks that are connected to the BC block that was passed on to the signal

Then, whenever it finds a connected block, it will send a signal to the antenna with the id that equals callback_antenna_id, a context variable that you need to pass on to the wired setup. It will forward the connected BC block that it found

#

This allows us to do many entirely different things, with minimal wired setups, to all of the connected blocks!

#

This setup can also be inspected in habbo.com: :roomid 79590533

#

As with all things, there surely would have been different ways to make this happen without using Context variables, such as:

  1. Giving all of the blocks a variable beforehand, in which the value is the same as the connected blocks
  2. Using a selector by variable ID

But again, this is a very simple example. What if the field is constantly moving? What if there are some parameters you could pass on to the Wired setup that determines the selected blocks? (such as: allowed directions to look towards, allowed types of furniture, allowed states)

Suddenly, it would not be as easy anymore! You'll find that this is actually a very scalable setup that will make your life much easier when building games with complex logics. And it can all run in parallel!

Callbacks can also be used to signalize when a Wired setup has finished executing. This can be very useful in setups where a certain signal chain needs to be executed before you can continue with some different, unrelated Wired stacks

#

But I'm getting ahead of myself! Signalizing when a wired setup has finished? Input parameters? That sounds a lot like... [functions](#1242050063988162610 message)