Working on a Encoding/Decoding Module

Module Name: EncodeDecode Module
Use: Encoding Instances into tables with descendants for things like DataStores, then decoding them into their proper Instance(s)

Copied from original “wiki” in module, did not feel like making a new one.

Method: :Encode(Instance ToEncode)
Description: Encodes the instance and it’s children to a table that can be saved via DataStores
Returns: Table for decoding

Method: :Decode(Table EncodedCode)
Description: Decodes the code from encoding into the actual instances
Returns: Instance from encode

Before encoding and decoding:

Script used for testing:

local M = require(game.Workspace.EncoderDecoderModule)
local Code = M:Encode(game.Workspace.TestModel)
wait(1)
game.Workspace.TestModel:remove()
wait(1)
local Ins = M:Decode(Code)
Ins.Parent = game.Workspace
  1. Parts
  2. Wedges
  3. CornerWedges
  4. TrussParts
  5. BlockMeshes
  6. CylinderMeshes
  7. SpecialMeshes
  8. Models
  9. Tools
  10. Hats

Added 8/10/14:
11. SurfaceGuis
12. ScreenGuis
13. Frames
14. ScrollingFrames

Added 8/11/14:
12. TextLabel
13. TextBox
14. ImageLabel
15. ImageButton
16. TextButton
17. Value Domain (ObjectValue do not save value)
18. Humanoids
19. CharacterMeshes
20. Configuration
21. Backpack
22. Hopperbins
23. BodyColors
24. Shirts
25. Pants
26. ShirtGraphics
27. Decals
28. Textures
29. Remote/Bindable Objects
30. Accoutrement
31. ForceFeild
32. AnimationController
33. Holes
34. ClickDetectors
35. Animations
36. Sounds
37. Fire
38. Sparkles
39. Smoke
40. SpawnLocations

  1. Scripts - Can’t get Source
  2. Localscripts - Can’t get Source
  3. ModuleScripts - Can’t get Source (I think, feel free to prove me wrong)
  4. ManualWelds/Welds/Motor6Ds/Glues - Can’t figure out getting and saving Part0 and Part1 with current system
  5. Unions/NegateOperations - Can’t get bit code, not able to be able to be imported ingame atm

Before I release it, I want to know if anyone has requests for things to add support for.
Also, anyone feel like this would be useful?

GUI objects would be useful.

Sounds good to me. :wink:
Luckily I can find most by see what I can insert into ReplicateFirst + ScreenGuis + SurfaceGuis

Edit: BillboardGuis and SurfaceGuis might come with a downside, not being coded with their Adornee.

You may find this useful:
http://codepad.org/fAzfUJsK

It’s a snippet from some code that I wrote for highly compressed rotation encoding. Using variable length encoding, It encodes a rotation very accurately but using only ~3.5 bytes on average for typical part rotations (1 byte for orthogonal rotations, 3 bytes for orthogonal-except-for-a-one-axis-rotation rotations, and 7 bytes for everything else).

Because, without a clever encoding like this, if you just do something like:

out = "CFrame.new("..tostring(cf)..")"
-- or
out = {T = 'CF', V = {cf:components()}}

You will end up taking a whopping ~60 bytes on average per CFrame to encode them, making it by far the most expensive part of the model to encode. At the very least make sure that you’re encoding the CFrames as Euler angles:

out = {cf.p.X, cf.p.Y, cf.p.Z, cf:toEulerAnglesXYZ()}

Since storing the actual rotation matrix stores a lot of redundant information for no additional accuracy.

Uh…

Backpack objects, I use them often.
Value class objects such as Bool, String,CFrame, Object, etc.

what do you use backpacks for? o.o

Models, settings folder, stuff.

Models? What’s wrong with the default models?

Settings: A much cleaner alternative is a module script. i.e.

local settings = {
matchSeconds = 1200;
defaultMoney = 40;
etc
}
return settings

Then, you can fetch those from either the client or server. Even without Filtering, clients won’t be able to update the settings on the server :slight_smile:

“Models? What’s wrong with the default models?”

It’s a really bad idea to use Models for “folder” / “container” purposes, because they have behavior associated with them that is should not be associated with those types of things. Namely: That if the last part in that model falls off the map and is deleted by the kill-floor at -500 the model will be deleted. This is a particularly common gotcha in Roblox game coding.

but, but I can’t drag parts into anything but models. Also, I think he means for stuff in storage and whatnot in the ReplicatedStorage/ServerStorage. Models there are perfectly fine right? I mean, they have :GetPrimaryPartCFrame() and whatnot, etc, but does that really make that much of a difference?

Nurp, I use them in Workspace and in tools for things like ammo and stuff…

I use configuration objects as folders.

I was able to re-write the module and get it to work where I have to edit one thing to add stuff, not 3 things.
Also compressed 500 lines into 150, time to add support for more stuff. :DDD

P0 and P1 can be done by linking a referance to what part of the table the associated parts are stored in, and when you re-load it into a game, have welds loaded last, so that the associated parts can be linked

That… will take me a while to figure out. :stuck_out_tongue:

I think it would work better if each part was assigned a unique ID. This way the format can be encoded into JSON.

Ok, time to just release it to the public, if anyone wants to, they can continue work to make it better. http://www.roblox.com/InstanceEncryption-Module-item?id=172325878

Is this the type of thing ScriptOn uses for his City of Robloxia game?

Not sure… possible, but probably not, lot less data to store things like positions and have a model bin. (I have done testing on that).