So recently, I encountered an odd issue which was breaking my game (Specifically my GCC game) - players were getting unusual amounts of potions, incorrect amount of candies, and more bugs were occurring.
After doing extensive research (8 hours of debugging and a case of Mountain Dew later), I found that tables now have an odd behavior that may/may not be intentional. If you set a table within a table from a variable that is set as a table, it acts as a pointer instead of a table.
Now, the previous behavior was that when you ran this code, each player would get a copy of the template player data that was a copy of the original. Now, the new behavior is that it acts as a pointer directly to the template player data instead of its own separate table. That means that if player 1 gets 10 candies, and player 2 joins after that event occurs, then player 2 will receive the player data of player 1.
Iâm not sure if this is intentional or not, but it sure as heck is annoying (I had to write a function to make a copy of the table so it wouldnât write to the original) - some clarification as to if this is the intended behavior or not would be greatly appreciated.
Itâs always acted this way, I donât know why youâre seeing something different now, regardless. I think that you should just be setting the table from within your function.
function copyTable(tab)
return {unpack(tab)}
end
[/quote]
This only works with numerical indices.
It should be noted that any members of the table that are tables themselves will still be âlinkedâ.[/quote]
function duplicateTable(t)
local duplicate = {}
for key,value in pairs(t) do
duplicate[key] = value
end
return duplicate
end