Wizgoose - Table that replicates and tracks itself

logo

Wizgoose

Validation

Wizgoose is a library that adds replication and change tracking to Luau tables through metatable magic. Said magical objects have Value property which knows when it’s changed, what changed, and how it changed, thus allowing it to signal changes, such as when property changes, or when an array has an item added into it or removed from, this applies both to server and client.

Resources

Example

-- Server.luau
local sessionData = Wizgoose.new("session-data", {
    timer = 0
})

for i = 100, 1, -1 do
    sessionData.Value.timer = i
    task.wait(1)
end

-- Client.luau
local sessionData = Wizgoose.get("session-data")
sessionData:Changed("timer"):Connect(function(seconds)
    print(seconds)
end)

This is experimental project that I do not actively maintain, therefore, use of this project in production is highly discouraged!

19 Likes

Isn’t this basically a ReplicaService with less features?
Replicate your states with ReplicaService! (Networking system) - Resources / Community Resources - DevForum | Roblox

5 Likes

It’s not the same, if you took time to see API of each module you would notice a somewhat major difference, especially the way you interact with them.

Primary goal of NetTbl is to focus on tables and remain minimalistic; as well as be simple, and easy to learn. You can think of Replica as IDE and NetTbl as a code editor. IDE does many different things and provides all kinds of features while code editor mostly focuses on code editing.

Pretty much the same thing can be said for those two, ReplicaService provides tons of features while NetTbl focuses on tables, replication, change tracking, minimalism, and simplicity; because it tries to simplify your workflow as much as possible.

Each system has it’s own pros and cons, therefore it’s up to you to decide what you need. If you need something more feature rich and advanced, use Replica, if you want something simple and minimalistic then go for NetTbl.

Creating Data

Replica.luau

local SessionData = ReplicaService.NewReplica({
    ClassToken = ReplicaService.NewClassToken("SessionData"),
    Data = {Value = 0},
    Replication = "All",
})

NetTbl.luau

local SessionData = NetTbl:Add("SessionData", { Timer = 0 })

Retrieving Data

Replica.luau

ReplicaController.ReplicaOfClassCreated("SessionData", function(sessionData)
	print(sessionData.Data.Timer) --> 0
end)

ReplicaController.RequestData()

NetTbl.luau

--[[
	You can call this function in multiple lua containers without worry,
	this is because NetTbl handles all of the magic for you!
]]
local SessionData = NetTbl:Get("SessionData")
print(SessionData.Value.Timer) --> 0

Reading Values

Replica.luau

print(SessionData.Data.Timer) --> 0

NetTbl.luau

print(SessionData.Value.Timer) --> 0

Changing Values

Replica.luau

for i = 100, 1, -1 do
	SessionData:SetValue("Timer", i)
end

NetTbl.luau

for i = 100, 1, -1 do
	SessionData.Value.Timer = i
end

Tracking Changes

Replica.luau

local function UpdateTimerDisplay(newValue, oldValue)
	print(newValue, oldValue) --> 2, 1
end

SessionData:ListenToChange("Timer", UpdateTimerDisplay)

UpdateTimerDisplay(SessionData.Data.Timer) -- Initialization

NetTbl.luau

--[[
	No need to initialize it yourself, you can pass true to the
	NetTbl:Track function and it will do it for you.
]]
SessionData:Track("Timer", function(newValue, oldValue)
	print(newValue, oldValue) --> 2, 1
end, true)
7 Likes

Is there a way to track, if a new value in the table has been inserted?

If not, then that would be a cool new feature if you can add that.

1 Like

Only if you implement that yourself as of right now.

Yes. Thank you for the feature request, I will implement this whenever I get time to work on it.

Sorry to bump, is there any word on if this module will be getting this feature supported of if it will be updated at all?

1 Like

It will be updated hopefully next month. The reason it is taking so long is because my schedule is filled up with work like AutoVehicle, and CarController, as they are far more used compared to NetTbl, I mean just look at their like counts.

Basically, the more popular the product is, the higher the priority it will have in my schedule. Additionally, my schedule is limited by school and other things that I don’t have control over.

Unless my dream of living off open source projects will happen where I will get enough money per month to be able to sustain myself, then I won’t have a lot of time to work on them, but I will still try my best.

I do understand that some of you here really need this feature and I will make sure to implement it, but I need to prioritize my more popular projects first before these.

If you want the feature earlier then you have few options:

  1. Make the product more popular.
  2. Implement it yourself and make a pull request.
  3. Donate me with a request to implement it.
3 Likes

NetTbl 2.0.0


As requested by @braveheart882474 @desinied, tracking when and what items are added or removed from an array is now possible.

  1. Renamed Track method to Changed.
  2. Added ItemAddedIn and ItemRemovedIn methods to allow for easy tracking of when, and what items are added or removed from particular array.
  3. Fixed “thread is not yieldable” error.
  4. Fixed major bug in change mapping algorithm that would cause trackers to not signal when something is removed.
  5. Replaced traditional callbacks with signal API, so that Connect, and Once can be used.
  6. Added GitHub repository for the project.
  7. Fixed a case that would allow you to infinitely yield the get method.
  8. Methods Add and Get were made static and names were changed to follow camelCase convention.
2 Likes

License has been changed to Mozilla Public License 2.0, as the previous one wasn’t entirely compatible with how Roblox works.

Wizgoose 2.1.0


You can now re-assign Value property with another table, meaning that library now supports this kind of operation as previously this caused the library to ignore the change.

object:Changed("money"):Connect(function()
    print("Money has changed") -- This will print!
end)

object.Value = {
    money = 0
}
1 Like

This is exactly what I have been looking for! Thank you so much for this resource, it is much appreciated!

1 Like

May I ask why ever since the latest update, now when I have two tables and I print the first table, it will print the second table

Lets say

local tbl1 = Wizgoose.new('a', { a = 1, b = 2 })
local tbl2 = Wizgoose.new('b', { c = 2, d = 3})

print(tbl1.Value)

it will return { c = 2, d = 3 }

Below is the screenshot

This is really cool I have done something similar with my save settings for this directory of 80 personalities except with objects and use a table to return the localized signal to know when to save an individual array.

1 Like

I was going to reply to this post but DevForum went down when I tried, but then forgot; apologizes about that. As for the bug you mentioned, that should’ve been fixed in the latest version which was not published to GitHub (I think?). Though, I have a latest version that you can try here:

Wizgoose-Latest.rbxm (10.1 KB)

Personally, I would not recommend using this library in production due to it being an experimental project that I currently do not maintain.

Do you have any plan to make something better, because I pretty like this module.