Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

[Yes or no] Shared vs _G? [closed]

Asked by 9 years ago

Hello,

I know shared and _G are almost the same, but is shared able to go client side and server side like _G cant?

-- Server side
shared.Asd = function()
    return "asd"
end

-- Client side
print(shared.Asd())

_G cannot do these things, but since shared is SO old and never been updated could it work under client and server being the same table?

Locked by MessorAdmin, XToonLinkX123, Perci1, and woodengop

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
4
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

No. Tables can store arbitrary objects and functions. Consider this on the server:

local blah = {}

function _G.set(x)
    blah = x
end

function _G.get()
    return blah
end

I could then do this on a client:

local mine = {}
_G.get().hello = mine
mine.blah = _G.get()

Now blah, which resides in the server's memory, refers to mine, in the client's memory (and vice versa). Managing this is sort of ridiculous and doesn't make any sense. When you say _G.get(), how long do you wait? What if the value has since changed?


You have to properly use RemoteEvent and RemoteFunctions. These give a safe, simple filter that connects the client and the server.

If you really are uncomfortable using them, you can of course do some magic with modulescripts / metatables / whatever you want to take advantage of RemoteFunctions behind-the-scenes.

0
Thank you much! MessorAdmin 598 — 9y
0
While it doesn't really make sense, I realized you can totally do this -- I'm writing a module script right now. (I wouldn't recommend it in practice -- it's cleaner and safer to use RemoteFunctions) BlueTaslem 18071 — 9y
0
Nevermind, this is nightmarish (cyclic tables + functions) BlueTaslem 18071 — 9y
Ad