Any practical uses for bindable events / functions?

I’ve known about bindables for quite some time now, however I have yet to actually use them in scripting. Module scripts seem to get the same job done pretty efficiently. What would be the best time to use a bindable event?

2 Likes

It just depends on your personal preferences for organizing your code. If you had one script to control rounds, another to control data handling, and another to control weapons, it is important to communicate between them. You can make data saving into an impersonal module and have the rounds system operate independently of the weapons, or you could have the data script handle all data in a way that is more customized to your game and you could have the rounds system communicate with the weapons system to coordinate who is alive and verify accidental deaths vs kills so you can determine the winner of the round. Up to you how you want to do it.

1 Like

I use them all the time to send data from one script to another. Or I use them in combination with remote events. I have a central remote event handler for a subset of events. It would be inefficient to sanity check the same event in 5 different places. Instead I can sanity check it in a central handler and then send out a Bindable that will notify the rest of my scripts of the event, which already passed checks and the respective handlers can do what they need with the data. Or I have a centralized event handler that sends data to the client but many scripts need to access it. Instead of doing

get all data needed
do some methods maybe
send out remote

in 5 scripts, I send out a bindable that’s being listened to in a centralized handler, which does all the methods and fires the remote event to the client.

1 Like

bindables are useful in situations where one character is doing something to another character

a few scenarios where this would be useful;
grabbing mechanics where the user has complete control over the other character
stuns, or fx that you don’t want to go away from debris

2 Likes

Speaking of bindables, they are powerful tools for signals, either client for client or server for server. You can use it to operate the game logic if multiple scripts or modules are used. This, however, depends on a lot of preference in organization.

1 Like

Totally agree.

I set up lots of mock ‘Services’ that simulate the syntax of an actual service. Creating events are really important, and one way to do this is through Signals which rely on Bindable events. It’s much easier for passing values to be executed as arguments of other functions versus relying on module integration in certain cases.

1 Like

Here’s an example from an obby game I programmed:

image

I prefer this to ModuleScripts because this lets you see the interface to the different code modules without reading source code. I don’t need to switch between scripts to remind myself what the different “methods” of each module is called, I can just see it in the explorer. Additionally, most of these “manager” type of modules have to run code of their own at runtime, i.e. they’re not strictly just dependencies of other scripts. If that was the case, I’d use a ModuleScript and I usually do for most of the code that I reuse across projects.

4 Likes