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 |
|
|
|
| 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 |
|
|
| |
|
| |
|
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
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 15 Jan 2015 03:48 PM |
BindableEvents and BindableFunctions.
I use them extensively. |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 15 Jan 2015 04:07 PM |
| Go on, use moduleScript based listeners I dare you. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 15 Jan 2015 05:32 PM |
| Look at my Select Items gui freemodels for an example of its other use. |
|
|
| Report Abuse |
|
|
|
| 15 Jan 2015 05:44 PM |
| @jus It still uses HttpService which needs server sided access. Path is is against OPs wishes. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
| |
|
|
| 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 |
|
|