Oficcer_F
(Oficcer_F)
November 22, 2019, 7:27pm
#1
Hello,
I noticed that my bindable function doesn’t work. So if I want to print a value given from a bindable function it print’s nil.
Here is my game:
ProblemBindableFunction.rbxl (17.4 KB)
Here is the script:
It seems like it “skips” one argument.
> sendMessageToScript2 = game.Workspace.SendMessageToScript2
> chosenNumber = sendMessageToScript2:Invoke(1,2,3,4,5,6,7)
>
>
> --script 2
> sendMessageToScript2 = game.Workspace.SendMessageToScript2
>
> function sendMessageToScript2:OnInvoke(number1, number2, number3, number4, number5, number6, number7)
> print(number7) --prints nil
> print(number3) --prints 4 (should've printed 3...)
> end
I’m not sure why this would happen, however my guess is because you are using Bindable:OnInvoke
instead of using Bindable.OnInvoke
. Notice the second case does not use a colon.
3 Likes
ForbiddenJ
(ForbiddenJ)
November 22, 2019, 7:38pm
#3
Your problem is that you are using a colon instead of a dot in this script. Because of this, you are triggering some “syntatic sugar” which causes the first argument to be passed to a hidden parameter called “self”, and then the rest are assigned to your parameters, which would look like a leftward shift in where your values end up.
I recommend you replace your colon with a dot to stop this behavior.
function sendMessageToScript2.OnInvoke( ...
4 Likes
i think the first thing in the parameter in the invoke script is referencing the player
1 Like
Oficcer_F
(Oficcer_F)
November 22, 2019, 7:57pm
#5
Thats only client-server communication I believe. Thought that might’ve been an error earlier on, but ruled that posibility out.
Thanks anyway!
1 Like
Oficcer_F
(Oficcer_F)
November 22, 2019, 7:58pm
#6
THANK YOU SO MUCH!
I have been trying to figure out this ***** bug for 6 hours! I am not kidding, why did it not throw an error??
And why is “synatic sugar” called syntatic sugar (just out of curiosity)
THANK YOU SO MUCH
ForbiddenJ
(ForbiddenJ)
November 22, 2019, 8:04pm
#7
An excerpt from the Lua reference manual.
The colon syntax is used for defining methods , that is, functions that have an implicit extra parameter self
. Thus, the statement
function t.a.b.c:f ( *params* ) *body* end
is syntactic sugar for
t.a.b.c.f = function (self, *params* ) *body* end
And oops, I misspelled “syntactic sugar.”
1 Like