I am confused on the Bindables in general. (Remotes might follow the same concept as well.)
Referring to this article on Bindables in DevForums,
An event can only be subscribed to by one other script at a time. When a second script subscribes to an already subscribed event, the first script will be unsubscribed.
So my understanding is a Bindable can subscribe or “listen” to one script at a time.
Does this mean only one script can Fire the event at a time, or only one script can Receive/Connect the event at a time?
When a new script is subscribed to the Bindable, can the previous subscription be assumed as closed?
I am not sure what that statement is talking about? Bindable events can be listened to / connected to by multiple scripts without closing other connections, and they can also be fired by different scripts. In this case, you can’t assume old connections are closed unless explicitly disconnected or by destroying the bindable itself.
There’s BindbaleEvenrs, and then there’s BindableFunctions.
BindableEvents, you can connect how many functions you want.
Another thing is that these connected functions run in another thread. (You can think of that as not affecting anything on the script you’re calling them from)
So if a connection in a BindableEvent yields, that won’t happen in the code you’re firing that event from.
BindableFunctions are NOT events, they work as a CALLBACK instead. So they will affect the script you’re calling them from, if the function “connected” yields, it will yield the script you called it from.
They are a function, therefore you can RETURN and get variables and info from them.
So yes, BindableFunctions only accept one callback.
I feel like the majority of you are misunderstanding the question. The question I am referring is specific to the subscription definition. I know it says an event can be subscribed to by one other script at a time.
I am just confused on how this “subscription” is working.
When working in a language such as Angular, you can use Observables to subscribe to a connection which opens a binding connection until the subscription is finished or closed.
While Roblox, I don’t really understand if when I Fire a Bindable event, yes since it is a BindableEvent, it just fires the BindableEvent and moves on. When I fire it, is firing it subscribing the BindableEvent to when I fire this event and then all events connected to the BindableEvent are fired?
When a second script subscribes to an already subscribed event, the first script will be unsubscribed.
Or is it when I am connecting to the event. Where based on the above definition, the only connector will be the most recently “subscribed”, connected event. So only the most recently defined event will run?
Or is it the 3rd option where, similar to BindableFunctions, there is only a binding agreement between one Fire method and one Connect method.
Multiple scripts can connect/listen to BindableEvents and will not disconnect others. Older connections will never be disconnected or overridden without purposefully doing so. Every connection/listener will run when the event is fired. This seems to be a documentation error and should be put under BindableFunctions instead.
I guess you can say it is the first option then? I am confused as to what you’re asking here. Firing the event does not subscribe anything. All :Fire() does is call all non-disconnected connections that were registered using :Connect() in their own “thread”. Connections registered by :Connect() will only ever be disconnected if you call :Disconnect() on any RBXScriptConnection. They may also be disconnected if an instance associated with that event such as .Changed is destroyed. You can assume that BindableEvents act pretty much the same as any Instance event such as .Changed.
Well, i use bindables for tweening UIs so i dont need to write code over and over 1000 times. I think i was wrong earlier, so you may be able to fire from different scripts. but im not sure about receiving.