Sooo... I have a Bindable Function called GetGamepasses, i want to make it so when i invoke the bindable function with my main script, it triggers another script and makes that script return a table to the main script. The return part wont work for me. Can somebody tell me how i would do that?
In order to use BindableFunctions, you should understand the purposes for which you should use them. Normally, you would use BindableFunctions when you want to organize your code and expose APIs for other scripts to use. ModuleScripts can also be used for this purpose, but here BindableFunctions are great too.
The following excerpt is from the API dump. This excerpt tells you the members specific to the BindableFunction class, and from this excerpt you can make an educated guess about how the members, and most importantly the class as a whole, work.
Class BindableFunction : Instance YieldFunction Tuple BindableFunction:Invoke(Tuple arguments) Callback Tuple BindableFunction.OnInvoke(Tuple arguments)
As hinted at by the API dump excerpt, BindableFunctions require a callback called OnInvoke
to be set. This, as you can probably guess, is what gets called when the Invoke
method is called. Below is an example use.
function script.Add.OnInvoke(a, b) -- one way to do it return a + b end function subtract(a, b) -- different way to do it return a - b end script.Subtract.OnInvoke = subtract
a = Script1.Add:Invoke(10, 20) b = Script1.Subtract:Invoke(20, 10) print( Script1.Add:Invoke( Script1.Subtract:Invoke(a, b), Script1.Subtract:Invoke(b, a) ) )
And with that, you know virtually all you need to know about BindableFunction objects!
Why not just use global variables?
In one script:
_G.Table = { "something", "other value", 1 }
In another:
print(_G.Table[1]) -- something print(_G.Table[2]) -- other value print(_G.Table[3]) -- 1