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 » Scripters
Home Search
 

Re: [?] Local Inter-Script Communication Strategies

Previous Thread :: Next Thread 
duckwit is not online. duckwit
Joined: 08 Aug 2008
Total Posts: 1310
15 Jan 2015 12:55 PM
Suppose that there are a number of unique LocalScript Instances, each wanting to trigger specific functionality and access data that the others contain.

What are the relative advantages and disadvantages of the following approaches:

(1) Using BindableEvents and BindableFunctions
(2) Using the local global table, _G
[(3) Other approaches?]

There is no need to consider interaction with the server in answering this problem.

Thank you for your time!
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
15 Jan 2015 12:59 PM
Use CustomEvents and CustomEventReceivers instead. They are much better.

_G is probably okay, but in my mind I just consider it a little outdated.
Report Abuse
epicbreaker is not online. epicbreaker
Joined: 23 Apr 2011
Total Posts: 2791
15 Jan 2015 01:01 PM
Aren't they deprecated?
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
15 Jan 2015 01:01 PM
Yes, I was joking.
Report Abuse
duckwit is not online. duckwit
Joined: 08 Aug 2008
Total Posts: 1310
15 Jan 2015 03:46 PM
@JarodOfOrbiter Is the latter statement of your post an example of your sly humour, too? I don't see why the seniority of the global table should be a reason not to use it.

My concern can be rephrased:

Is there, when it seems so much more convenient to use the global table, any good reason to create more instances and use Bindable Events and Functions?
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
15 Jan 2015 03:48 PM
BindableEvents and BindableFunctions.

I use them extensively.
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
15 Jan 2015 03:55 PM
Since you only for method (not "efficient" methods) you could make a message exchanging system though, with a Model in LocalPlayer and some Values with .Changed
Report Abuse
duckwit is not online. duckwit
Joined: 08 Aug 2008
Total Posts: 1310
15 Jan 2015 03:56 PM
Thank you for the suggestion, @digpoe, but at the moment I am most interested in "Why?" I'd like to know your reasoning for why using BindableEvents and BindableFunctions is better than manipulating everything via the global table.

I have respect for you as one who is familiar with Lua, so I value your input.
Report Abuse
duckwit is not online. duckwit
Joined: 08 Aug 2008
Total Posts: 1310
15 Jan 2015 03:58 PM
@warspyking Obviously, one criteria for choosing a system is to minimise both time and and space consumption.
Report Abuse
verbalAKspray is not online. verbalAKspray
Joined: 09 Jul 2014
Total Posts: 23685
15 Jan 2015 04:03 PM
I don't know how efficient globals are, but I'd use that, less instances and easier
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
15 Jan 2015 04:07 PM
Go on, use moduleScript based listeners I dare you.
Report Abuse
justin7674 is not online. justin7674
Joined: 26 May 2008
Total Posts: 349
15 Jan 2015 05:03 PM
I use JSON tables in a string value with .changed event.
It allows me to store my http requests and what not so that all of
the scripts making use of my shouting api don't need to make their own requests over and over for the same information that gets displayed in the user guis.

To see how I use it you can check out Shoutboard in my freemodels.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
15 Jan 2015 05:09 PM
No, the last one was not my humor. I was saying that in my mind I associate it with being old and outdated, but I was explaining that I can't really think of any reason not to use it.
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
15 Jan 2015 05:12 PM
It's slow. That's always a good enough reason for me.
(Performance aware Skye for days)
Report Abuse
duckwit is not online. duckwit
Joined: 08 Aug 2008
Total Posts: 1310
15 Jan 2015 05:20 PM
@justin7674 That is a novel proposition, thank you for sharing that.

@eLunate So, calling a function in the global table is slower than invoking a RemoteFunction? Perhaps, if you can, you could elaborate on your understanding of the underlying mechanics that cause this difference in performance, or provide some test that would indicate such a difference. I have seen your skills at play in the forums over the last few weeks in particular, nonetheless, I would rather not take your word for it.

Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
15 Jan 2015 05:23 PM
Sadly, @Justin, @duckwit Justin's idea would not work. You specified not to interact with the sever to answer this, which Justin did, because HttpService is server-sided only.
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
15 Jan 2015 05:24 PM
The global table is always a bit weird. Anyhow, I wouldn't be sure to say that _G is certainly slower than a BindableFunction (Even though they -should- get invoked through the C layer), but I would say there are probably faster or more elegant systems out there.

The issue is where you want the invokation to be handled, I guess.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
15 Jan 2015 05:27 PM
What is "shared" and why is it almost never used? Is it the same table as _G? Is it the same functionally as _G?
Report Abuse
justin7674 is not online. justin7674
Joined: 26 May 2008
Total Posts: 349
15 Jan 2015 05:30 PM
@war actually I used that method for my local scripts to retrieve information from the server. It works both ways
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
15 Jan 2015 05:32 PM
@Jarod There's 4 types of variables in which people continue to mess up on all the time.

local: variables defined with the local keyword become local to the scope:
local x = 5

gloabal: variables available throughout the script:
x = 5

shared: variables defined in _G. _G is local to the client, and the server has one. So all server scripts have the same _G, all of one player's LoalScripts have a _G, all of another's LocalScripts have a _G (see what I mean):
_G.x = 5


The other type of value is an upvalue, which I won't get into for the sake of basic scripters who may end up reading this.
Report Abuse
justin7674 is not online. justin7674
Joined: 26 May 2008
Total Posts: 349
15 Jan 2015 05:32 PM
Look at my Select Items gui freemodels for an example of its other use.
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
15 Jan 2015 05:44 PM
@jus It still uses HttpService which needs server sided access. Path is is against OPs wishes.
Report Abuse
Viscoelastic is not online. Viscoelastic
Joined: 04 May 2012
Total Posts: 269
15 Jan 2015 05:46 PM
No, you don't understand. :(

What is the difference between shared and _G? Why is shared almost never used.

shared.Example = 10
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
15 Jan 2015 06:00 PM
_G is shared lol?
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
15 Jan 2015 06:06 PM
Oh sorry, yea shared is basically the same as _G

It was basically _G but before _G used to contain global functions and stuck which all scripts had access to WITHOUT indexing _G

AKA in one script you can have this:

_G.Func = "Hi"


And in another

repeat wait() until Func
Func()


_G works differently now due to abuse/complications. It's the same as shared, although not marked as deprecated, nobody really uses shared anymore.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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