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

How should I make whole tables go through RemoteEvents/RemoteFunctions?

Asked by 7 years ago
Edited 7 years ago

I've been working on a game all year on Roblox. I've just finished the server-side of it, which holds all the data, and now I'm working on the client side, downloading and displaying the data.

So it came as a real bummer that I can't just pass a table in it's entirety through a RemoteEvent or RemoteFunction to download the data from the server to client. All the metatables I worked hard on are gone, and the class structure I've been developing gets ruined.

However, you can pass simple tables that hold data across the client-server boundary. At an arbitrary level, everything my tables hold are compromised of these simple pieces of data (strings, numbers, etc.). They are all named by keys too.

Because of this, isn't it possible to conserve a table using a pack/unpack script?

A pack script could transfer the table's data alone, and put it's metatables also as pieces of data inside of the table (and not applied to the table). The unpack function reverses this proccess.

The process could be recursive if there are tables stored within tables for this scenario.

So, is this a good way to work around the system, or am I missing something?

0
You can send a table just not a mixed table, it is explained at the bottom of http://wiki.roblox.com/index.php?title=RemoteFunction_and_RemoteEvent_Tutorial#Limitations User#5423 17 — 7y

2 answers

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
7 years ago
Edited 7 years ago

Yes, a serialize/deserialize system is an approach that would work. This is how it'd done in "real" systems, too.

This answer concerns this.

It is impossible to send functions over the network (because of closures). It's difficult to send cyclic structures. As a result, you're limited to sending trees/lists of plain old data, like numbers, strings, and booleans.

You can tag this structure with the "type" of object it is, and the receiving end can turn this data back into the object you want.


I think, however, most of the time you don't really need to send objects with behavior over the network.

Messages are messages, they're simply informing you about information that has happened. Information doesn't usually need behavior.

It may be most appropriate as the argument to a constructor/factory of something that does have behavior.

0
This is definitely true. All I needed was a way to read the data of the tables so that I could apply it to GUI's in the client. Now that I think of it, I don't really need metatables either, rather than the value of __index (to preserve class structure) randomsmileyface 375 — 7y
Ad
Log in to vote
-1
Answered by 7 years ago

Try sending the table parsed as JSON using HttpService's JSONEncode.

0
This should be a comment. RubenKan 3615 — 7y

Answer this question