DT/NetworkVar Changes (#1787)
This is an attempt to close garrysmod-requests/issues#798. This allows you to omit the slot of DT/NetworkVars, which simplifies DataTable inheritance. ```Entity:IsDTVarSlotUsed(typename, slot)``` and minor optimizations are also included.
The DT/NetworkVars slot parameter can either be nil or completely omitted:
```
local ENT = {}
ENT.Type = "anim"
function ENT:SetupDataTables()
self:NetworkVar("Int", 1, "Base1")
self:NetworkVar("Int", 3, "Base2")
self:NetworkVar("Int", 5, "Base3")
self:NetworkVar("Float", 0, "Base4")
self:NetworkVar("Float", 1, "Base5")
if SERVER then
self:SetBase1(1)
self:SetBase2(2)
self:SetBase3(3)
self:SetBase4(4.4)
self:SetBase5(5.5)
end
end
function ENT:Initialize()
print(self, self:GetClass())
for i=0, 31 do
if self:IsDTVarSlotUsed("Int", i) then
print("Int " .. i .. " used", self:GetDTInt(i))
end
end
for i=0, 31 do
if self:IsDTVarSlotUsed("Float", i) then
print("Float " .. i .. " used", self:GetDTFloat(i))
end
end
PrintTable(self:GetNetworkVars())
end
scripted_ents.Register(ENT, "github_test")
local ENT = {}
DEFINE_BASECLASS("github_test")
ENT.Base = "github_test"
function ENT:SetupDataTables()
BaseClass.SetupDataTables(self)
self:NetworkVar("Int", nil, "Test1") -- backfills Int 0
self:NetworkVar("Int", "Test2") -- backfills Int 2
self:NetworkVar("Int", "Test3") -- backfills Int 4
self:NetworkVar("Int", "Test4") -- uses Int 6
-- Int 0 through 6 are used
self:NetworkVar("Float", "Test5") -- uses Float 2
self:NetworkVar("Float", "Test6") -- uses Float 3
-- Float 0 through 3 are used
if SERVER then
self:SetTest1(-1)
self:SetTest2(-2)
self:SetTest3(-3)
self:SetTest4(-4)
self:SetTest5(-5.5)
self:SetTest6(-6.6)
end
end
scripted_ents.Register(ENT, "github_test_child")
```