generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: ~ Bindable Function Tutorial ~

Previous Thread :: Next Thread 
nightname is not online. 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 is not online. LPGhatguy
Forum Moderator
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 is not online. 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 is not online. 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 is not online. 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
Penguine236 is not online. Penguine236
Joined: 13 Apr 2011
Total Posts: 1303
19 Feb 2012 02:44 PM
I feel your pain DX. I DON'T GET METATABLES!
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
21 Feb 2012 10:46 AM
I don't get it. What's with all the arrays!!!
Report Abuse
nightname is not online. 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
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
21 Feb 2012 01:59 PM
Tables = Arrays

I just have no idea what you're doing.
Report Abuse
tehepicford is not online. tehepicford
Joined: 26 Aug 2011
Total Posts: 1486
21 Feb 2012 01:59 PM
You fail!
Report Abuse
nightname is not online. 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
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
21 Feb 2012 02:44 PM
Could you put an article on the wiki?
Report Abuse
DXPower is not online. 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 is not online. 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 is not online. 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 is not online. 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
epicfail22 is not online. epicfail22
Joined: 25 Sep 2009
Total Posts: 3739
22 Mar 2012 06:19 PM
Never knew bout this. Tracked :3
Report Abuse
RA2lover is not online. 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
roblox88888 is not online. roblox88888
Joined: 23 Jun 2008
Total Posts: 43
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
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
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 is not online. 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
ninjaknight101 is not online. ninjaknight101
Joined: 04 Apr 2011
Total Posts: 1281
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
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
10 Oct 2012 10:13 PM
wat
Report Abuse
NightPyro is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image