nightname
|
  |
| Joined: 10 Jun 2008 |
| Total Posts: 8960 |
|
|
| 18 Feb 2012 03:53 PM |
The BindableFunction object contains two properties that we are interested in, these two properties include:
The method Invoke(args); The callback OnInvoke(args);
By setting a function to the callback "OnInvoke", you can invoke that function using the method "Invoke".
Here is an example:
local func = Instance.new("BindableFunction", workspace);
func.OnInvoke = function(arg) print(arg) end
func:Invoke("Hi")
--
That piece of code will print "Hi" onto the output. This works because the function set to OnInvoke prints out the argument inputted. When we invoke the function, the callback will fire the function and will print "Hi".
|
|
|
| Report Abuse |
|
|
LPGhatguy
|
  |
 |
| Joined: 27 Jun 2008 |
| Total Posts: 4725 |
|
|
| 18 Feb 2012 04:25 PM |
| So it's essentially a ROBLOX object version of a Lua function? |
|
|
| Report Abuse |
|
|
DXPower
|
  |
| Joined: 21 Oct 2008 |
| Total Posts: 2866 |
|
|
| 18 Feb 2012 04:27 PM |
So... It's a function that can be run from another script?
You can do this already with _G table.
_G["Test"] = function(...) local t = ... return table.concat(t, ' ') end
local func = _G["Test"] print(func({"Hi", "person", " This", " Is fun!"}))
Noob Virus Download Complete. |
|
|
| Report Abuse |
|
|
nightname
|
  |
| Joined: 10 Jun 2008 |
| Total Posts: 8960 |
|
|
| 18 Feb 2012 05:09 PM |
No, it is actually pretty useful. You now have functions as objects - this allows us to do inter-scripts stuff.
Also, since BindableEvent is broken - here is my version of it... It is not done yet, but it works!
event = { stuff = { func, connect = function(arg) arg(); end, fired = false, ready = false }, }
function event:Fire(arg) if event.stuff.ready then event.stuff.func(arg) else error("No function assigned to Event.", 1) end end
setmetatable(event, { __newindex = function(tab, ind, val) if (ind == "Event" and type(val) == "function") then event.stuff.func = val; ready = true; elseif ind ~= "Event" then error(ind.." is not a valid member of Event.",0); elseif type(val) ~= "function" then error("Event only accepts functions as a value."); end end })
--- --[[HERE IS WHERE THE FUN STARTS!]] ---
event.Event = function(arg) print(arg) end
event:Fire("Hi")
|
|
|
| Report Abuse |
|
|
DXPower
|
  |
| Joined: 21 Oct 2008 |
| Total Posts: 2866 |
|
|
| 19 Feb 2012 10:14 AM |
AGH! METATABLES HURT MY MIND! D: I CAN'T UNDERSTAND METATABLES AT ALL! ): |
|
|
| Report Abuse |
|
|
|
| 19 Feb 2012 02:44 PM |
| I feel your pain DX. I DON'T GET METATABLES! |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2012 10:46 AM |
| I don't get it. What's with all the arrays!!! |
|
|
| Report Abuse |
|
|
nightname
|
  |
| Joined: 10 Jun 2008 |
| Total Posts: 8960 |
|
|
| 21 Feb 2012 01:54 PM |
"I don't get it. What's with all the arrays!!!"
They are a bunch of tables and metatables. What is so hard about them? Anyway, maybe I should release the new version - but I have not implemented Objects yet.
._. |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2012 01:59 PM |
Tables = Arrays
I just have no idea what you're doing. |
|
|
| Report Abuse |
|
|
| |
|
nightname
|
  |
| Joined: 10 Jun 2008 |
| Total Posts: 8960 |
|
|
| 21 Feb 2012 02:04 PM |
"I just have no idea what you're doing."
I was recreating the BindableEvent object, because it was broken. Now, what else is hard? |
|
|
| Report Abuse |
|
|
|
| 21 Feb 2012 02:44 PM |
| Could you put an article on the wiki? |
|
|
| Report Abuse |
|
|
DXPower
|
  |
| Joined: 21 Oct 2008 |
| Total Posts: 2866 |
|
|
| 21 Feb 2012 04:48 PM |
| I under stand tables and arrays completely, I just can't understand metatables. D: |
|
|
| Report Abuse |
|
|
nightname
|
  |
| Joined: 10 Jun 2008 |
| Total Posts: 8960 |
|
|
| 22 Feb 2012 05:46 PM |
| An article about what? There are already articles about metatables and metamethods. |
|
|
| Report Abuse |
|
|
shrimpoop
|
  |
| Joined: 28 Sep 2008 |
| Total Posts: 1307 |
|
|
| 22 Feb 2012 05:50 PM |
| I don't understand how built in functions can get broken. |
|
|
| Report Abuse |
|
|
nightname
|
  |
| Joined: 10 Jun 2008 |
| Total Posts: 8960 |
|
|
| 22 Feb 2012 05:53 PM |
"I don't understand how built in functions can get broken."
What reason stops them from not breaking? Anyway, it is not just BindableEvent. All events currently do not run in Edit mode - which means you'll have to debug in solomode/playmode.
|
|
|
| Report Abuse |
|
|
|
| 22 Mar 2012 06:19 PM |
| Never knew bout this. Tracked :3 |
|
|
| Report Abuse |
|
|
RA2lover
|
  |
| Joined: 09 Nov 2008 |
| Total Posts: 1254 |
|
|
| 05 Aug 2012 03:32 PM |
| megabump. are they still borked up on edit mode? |
|
|
| Report Abuse |
|
|
|
| 05 Sep 2012 06:57 AM |
EASY WAY:
function _G.MyFunction(arg) print(arg) end
and on Command Toolbar put this: _G.MyFunction("Hello World!") and it will result in the output: Hello World! --------Global Functions--------- and on wiki its NOT REPLICATED .. >_<
A BindableFunction is a ROBLOX object that allows you to give access to functions to external scripts. Functions put in BindableFunctions will not be replicated, therefore making it impossible to use these objects to share functions between many clients. Functions are invoked through the Invoke method, which calls the OnInvoke callback. |
|
|
| Report Abuse |
|
|
|
| 05 Sep 2012 09:20 AM |
What I don't understand is why the object isn't passed to the function when you invoke it. It defies the rules of Lua. |
|
|
| Report Abuse |
|
|
eJorge
|
  |
| Joined: 09 Jun 2011 |
| Total Posts: 5966 |
|
|
| 05 Sep 2012 11:53 AM |
| Oh, can you use BindableFunctions to share functions with LocalScripts? |
|
|
| Report Abuse |
|
|
|
| 05 Sep 2012 02:33 PM |
| I use bindable functions when trying to communicate with the client, because (someone already said) _G doesn't replicate! Argh |
|
|
| Report Abuse |
|
|
| |
|
NightPyro
|
  |
| Joined: 22 Apr 2012 |
| Total Posts: 183 |
|
|
| 10 Oct 2012 11:28 PM |
| :D That is kinda cool if you can see what he is doing. |
|
|
| Report Abuse |
|
|
adark
|
  |
| Joined: 13 Jan 2008 |
| Total Posts: 6412 |
|
|
| 11 Oct 2012 12:41 AM |
@AgentFireFox, might it have something to do with OnInvoke being a callback to the Invoke() method? I think that Invoke() *does* take the BindableFunction as the first parameter, and just passes the rest to the OnInvoke callback in the specified BindableFunction...
Bah, programming.
Any who, while they *can* mimic the _G and shared tables, they are useful in that they can run a LOCAL function when called by a GLOBAL script, and vice-versa.
If I had learned about these sooner, my Kiseki reboot may have been a lot less painful and a lot more successful than it was. |
|
|
| Report Abuse |
|
|