So I was watching this datastore tutorial and around the 6:05 timestamp of the video, he just pastes these two functions (PrintTableFunction and PrintTable)out of no where without any in-depth explanation claiming that it’s to help test out the datastore code. But I really want to understand how it works,(excerpt):
local function PrintTableFunction(Table,string)
for i,v in pairs(Table) do
if type(v) == "table" then
print(string,i," : ",v,":::")
PrintTableFunction(v, string.." ")
else
print(string,i," : ",v)
end
end
end
local function PrintTable(Table)
print()print()PrintTableFunction(Table, "")print()print()
end
Players.PlayerAdded:Connect(function(Player)
LoadData(Player)
ServerData[Player].Coins = ServerData[Player].Coins + 5
PrintTable(ServerData[Player])
end)
Players.PlayerRemoving:Connect(function(Player)
SaveData(Player)
end)
The code within these 2 functions make little sense to me, why equate type(v) to the string “table”, what does type() even do? What’s it meant to do? And I don’t get the ensuing code with this odd print statement print(string,i," : ",v,":::") . Not to mention, I didn’t know that calling a function within itself was possible, the v,string…""?
Well I could go on further but then it would be a lot more waffle than there already is, in short, it’s all very confusing to me. Would be great if someone could break both of those functions down for me and explain how exactly they test out the datastore.
