0

# How would I return a value through a bindable function?

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?

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

2
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
end

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


## Script 2:

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


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

0

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

0
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
0
What do you mean? Could you show us the code? PiggyJingles 358 — 7y
yeet truck