Log in to vote

How would I return a value through a bindable function?

Asked by 7 years ago

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?

If you are talking in reference to your last question, you need to use a RemoteFunction, not a BindableFunction. User#11893 186 — 7y
If not, then please provide some code so we can answer your question correctly. User#11893 186 — 7y

3 answers

Log in to vote
Answered by
blocco 185
7 years ago

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.

BindableFunction API dump

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)

Example of BindableFunction Use

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.

Script 1:

function script.Add.OnInvoke(a, b) -- one way to do it
    return a + b

function subtract(a, b) -- different way to do it
    return a - b
script.Subtract.OnInvoke = subtract

Script 2:

a = Script1.Add:Invoke(10, 20)
b = Script1.Subtract:Invoke(20, 10)
        Script1.Subtract:Invoke(a, b),
        Script1.Subtract:Invoke(b, a)

And with that, you know virtually all you need to know about BindableFunction objects!

Log in to vote
Answered by 7 years ago

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
Aha, i thought someone would say that... I've tried that before, the script is too complicated so i can't really use them.. 1GREENBOB123456 15 — 7y
What do you mean? Could you show us the code? PiggyJingles 358 — 7y
Log in to vote
Answered by 1 year ago
yeet truck

Answer this question