Discord
Steam
/
Garry's Mod
/
Developers
/
Why is my tabl..
Login/Join
Event Log
Why is my table copying its subkeys into each table subkey?
2 replies, posted
Search
In This Thread
[CODE] local function TableFullCopy( outertable ) local tbl = {} for k,v in pairs( outertable ) do if istable(v) then tbl[k] = TableFullCopy(v) else tbl[k] = v end end return tbl end later.... if !TFAVOX_IsValid(ply) or !ply.TFAVOX_Sounds then if TFAVOX_Models[ply:GetModel()] then ply.TFAVOX_Sounds = TableFullCopy( TFAVOX_Models[ply:GetModel()] ) end end [/CODE] Source Table: [CODE] models/player/tfa_seds_ow_dva.mdl: damage: 0: delay = 0.5 sound = PlayerDamage.DVa 1: delay = 1 sound = PlayerDamageHead.DVa 2: delay = 1 sound = PlayerDamageChest.DVa 3: delay = 1 sound = PlayerDamageChest.DVa 4: delay = 1 sound = PlayerDamageLeftArm.DVa 5: delay = 1 sound = PlayerDamage.DVa 6: delay = 1 sound = PlayerDamageLeftLeg.DVa 7: delay = 1 sound = PlayerDamage.DVa 10: delay = 0.5 sound = PlayerDamage.DVa main: crithealth: delay: 1 = 3.5 2 = 5 sound = PlayerLowHP.DVa crithit: delay: 1 = 3.5 2 = 5 sound = PlayerCritHP.DVa death: sound = PlayerDeath.DVa fall: sound = PlayerFall.DVa heal: sound = PlayerHealed.DVa healmax: sound = PlayerHealedMax.DVa jump: delay = 1 sound = PlayerJump.DVa noammo: sound = PlayerNoAmmo.DVa pickup: sound = PlayerPickUp.DVa reload: delay = 2 sound = PlayerReload.DVa spawn: sound = PlayerSpawn.DVa step: sound = PlayerWalk.DVa murder: ally: delay = 3 sound = PlayerMurder.DVa combine: delay = 3 sound = PlayerMurder.DVa cp: delay = 3 sound = PlayerMurder.DVa generic: delay = 3 sound = PlayerMurder.DVa headcrab: delay = 3 sound = PlayerMurder.DVa manhack: delay = 3 sound = PlayerMurder.DVa scanner: delay = 3 sound = PlayerMurder.DVa sniper: delay = 3 sound = PlayerMurder.DVa turret: delay = 3 sound = PlayerMurder.DVa zombie: delay = 3 sound = PlayerMurder.DVa spot: ally: delay = 2 sound = PlayerAlly.DVa combine: sound = PlayerEnemyOther.DVa cp: sound = PlayerEnemyOther.DVa generic: sound = PlayerEnemyOther.DVa headcrab: sound = PlayerEnemyOther.DVa manhack: sound = PlayerEnemyOther.DVa scanner: sound = PlayerEnemyOther.DVa sniper: sound = PlayerEnemyOther.DVa turret: sound = PlayerEnemyOther.DVa zombie: taunt: 53: sound = PlayerTauntForward.DVa 54: sound = PlayerTauntGroup.DVa 55: sound = PlayerTauntHalt.DVa 1610: sound = PlayerTauntAgree.DVa 1611: sound = PlayerTauntBecon.DVa 1612: sound = PlayerTauntBow.DVa 1613: sound = PlayerTauntDisAgree.DVa 1614: sound = PlayerTauntSalute.DVa 1615: sound = PlayerTauntWave.DVa 1616: sound = PlayerTauntPersistence.DVa 1617: sound = PlayerTauntMuscle.DVa 1618: sound = PlayerTauntLaugh.DVa 1619: 1620: sound = PlayerTauntCheer.DVa [/code] Result: [code] damage: 0: delay = 0.5 sound = PlayerDamage.DVa 1: delay = 1 sound = PlayerDamageHead.DVa 2: delay = 1 sound = PlayerDamageChest.DVa 3: delay = 1 sound = PlayerDamageChest.DVa 4: delay = 1 sound = PlayerDamageLeftArm.DVa 5: delay = 1 sound = PlayerDamage.DVa 6: delay = 1 sound = PlayerDamageLeftLeg.DVa 7: delay = 1 sound = PlayerDamage.DVa 10: delay = 0.5 sound = PlayerDamage.DVa damage: 0: delay = 0.5 sound = PlayerDamage.DVa 1: delay = 1 sound = PlayerDamageHead.DVa 2: delay = 1 sound = PlayerDamageChest.DVa 3: delay = 1 sound = PlayerDamageChest.DVa 4: delay = 1 sound = PlayerDamageLeftArm.DVa 5: delay = 1 sound = PlayerDamage.DVa 6: delay = 1 sound = PlayerDamageLeftLeg.DVa 7: delay = 1 sound = PlayerDamage.DVa 10: delay = 0.5 sound = PlayerDamage.DVa main: crithealth: delay: 1 = 3.5 2 = 5 sound = PlayerLowHP.DVa crithit: delay: 1 = 3.5 2 = 5 sound = PlayerCritHP.DVa death: sound = PlayerDeath.DVa fall: sound = PlayerFall.DVa heal: sound = PlayerHealed.DVa healmax: sound = PlayerHealedMax.DVa jump: delay = 1 sound = PlayerJump.DVa noammo: sound = PlayerNoAmmo.DVa pickup: sound = PlayerPickUp.DVa reload: delay = 2 sound = PlayerReload.DVa spawn: sound = PlayerSpawn.DVa step: sound = PlayerWalk.DVa murder: ally: delay = 3 sound = PlayerMurder.DVa combine: delay = 3 sound = PlayerMurder.DVa cp: delay = 3 sound = PlayerMurder.DVa generic: delay = 3 sound = PlayerMurder.DVa headcrab: delay = 3 sound = PlayerMurder.DVa manhack: delay = 3 sound = PlayerMurder.DVa scanner: delay = 3 sound = PlayerMurder.DVa sniper: delay = 3 sound = PlayerMurder.DVa turret: delay = 3 sound = PlayerMurder.DVa zombie: delay = 3 sound = PlayerMurder.DVa spot: ally: delay = 2 sound = PlayerAlly.DVa combine: sound = PlayerEnemyOther.DVa cp: sound = PlayerEnemyOther.DVa generic: sound = PlayerEnemyOther.DVa headcrab: sound = PlayerEnemyOther.DVa manhack: sound = PlayerEnemyOther.DVa scanner: sound = PlayerEnemyOther.DVa sniper: sound = PlayerEnemyOther.DVa turret: sound = PlayerEnemyOther.DVa zombie: taunt: 53: sound = PlayerTauntForward.DVa 54: sound = PlayerTauntGroup.DVa 55: sound = PlayerTauntHalt.DVa 1610: sound = PlayerTauntAgree.DVa 1611: sound = PlayerTauntBecon.DVa 1612: sound = PlayerTauntBow.DVa 1613: sound = PlayerTauntDisAgree.DVa 1614: sound = PlayerTauntSalute.DVa 1615: sound = PlayerTauntWave.DVa 1616: sound = PlayerTauntPersistence.DVa 1617: sound = PlayerTauntMuscle.DVa 1618: sound = PlayerTauntLaugh.DVa 1619: 1620: sound = PlayerTauntCheer.DVa main: crithealth: delay: 1 = 3.5 2 = 5 sound = PlayerLowHP.DVa crithit: delay: 1 = 3.5 2 = 5 sound = PlayerCritHP.DVa death: sound = PlayerDeath.DVa fall: sound = PlayerFall.DVa heal: sound = PlayerHealed.DVa healmax: sound = PlayerHealedMax.DVa jump: delay = 1 sound = PlayerJump.DVa noammo: sound = PlayerNoAmmo.DVa pickup: sound = PlayerPickUp.DVa reload: delay = 2 sound = PlayerReload.DVa spawn: sound = PlayerSpawn.DVa step: sound = PlayerWalk.DVa murder: ally: delay = 3 sound = PlayerMurder.DVa combine: delay = 3 sound = PlayerMurder.DVa cp: delay = 3 sound = PlayerMurder.DVa damage: 0: delay = 0.5 sound = PlayerDamage.DVa 1: delay = 1 sound = PlayerDamageHead.DVa 2: delay = 1 sound = PlayerDamageChest.DVa 3: delay = 1 sound = PlayerDamageChest.DVa 4: delay = 1 sound = PlayerDamageLeftArm.DVa 5: delay = 1 sound = PlayerDamage.DVa 6: delay = 1 sound = PlayerDamageLeftLeg.DVa 7: delay
Side note, you could use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/table/Copy]table.Copy[/url] instead of your own function. It supports additional stuff like recursive structures by [url=https://github.com/garrynewman/garrysmod/blob/451b4ff5d1aea7b9b06a8024ef706c248a79647e/garrysmod/lua/includes/extensions/table.lua#L36]keeping track of what it's copying[/url] and also [url=https://github.com/garrynewman/garrysmod/blob/451b4ff5d1aea7b9b06a8024ef706c248a79647e/garrysmod/lua/includes/extensions/table.lua#L28]supports metatables[/url]. But if you don't need that stuff it's fine (and probably better) to use your own. Aside from that, it seems like there is something else causing your issue that isn't related to what you've provided. I just tested your function with the table given and it worked fine. Test code: [code] local function TableFullCopy( outertable ) local tbl = {} for k,v in pairs( outertable ) do if istable(v) then tbl[k] = TableFullCopy(v) else tbl[k] = v end end return tbl end local test = { damage = { [0] = { delay = 0.5, sound = "PlayerDamage.DVa", }, [1] = { delay = 1, sound = "PlayerDamageHead.DVa", }, [2] = { delay = 1, sound = "PlayerDamageChest.DVa", }, [3] = { delay = 1, sound = "PlayerDamageChest.DVa", }, [4] = { delay = 1, sound = "PlayerDamageLeftArm.DVa", }, [5] = { delay = 1, sound = "PlayerDamage.DVa", }, [6] = { delay = 1, sound = "PlayerDamageLeftLeg.DVa", }, [7] = { delay = 1, sound = "PlayerDamage.DVa", }, [10] = { delay = 0.5, sound = "PlayerDamage.DVa", }, }, main = { crithealth = { delay = { [1] = 3.5, [2] = 5, }, sound = "PlayerLowHP.DVa", }, crithit = { delay = { [1] = 3.5, [2] = 5, }, sound = "PlayerCritHP.DVa", }, death = { sound = "PlayerDeath.DVa", }, fall = { sound = "PlayerFall.DVa", }, heal = { sound = "PlayerHealed.DVa", }, healmax = { sound = "PlayerHealedMax.DVa", }, jump = { delay = 1, sound = "PlayerJump.DVa", }, noammo = { sound = "PlayerNoAmmo.DVa", }, pickup = { sound = "PlayerPickUp.DVa", }, reload = { delay = 2, sound = "PlayerReload.DVa", }, spawn = { sound = "PlayerSpawn.DVa", }, step = { sound = "PlayerWalk.DVa", }, }, murder = { ally = { delay = 3, sound = "PlayerMurder.DVa", }, combine = { delay = 3, sound = "PlayerMurder.DVa", }, cp = { delay = 3, sound = "PlayerMurder.DVa", }, generic = { delay = 3, sound = "PlayerMurder.DVa", }, headcrab = { delay = 3, sound = "PlayerMurder.DVa", }, manhack = { delay = 3, sound = "PlayerMurder.DVa", }, scanner = { delay = 3, sound = "PlayerMurder.DVa", }, sniper = { delay = 3, sound = "PlayerMurder.DVa", }, turret = { delay = 3, sound = "PlayerMurder.DVa", }, zombie = { delay = 3, sound = "PlayerMurder.DVa", }, }, spot = { ally = { delay = 2, sound = "PlayerAlly.DVa", }, combine = { sound = "PlayerEnemyOther.DVa", }, cp = { sound = "PlayerEnemyOther.DVa", }, generic = { sound = "PlayerEnemyOther.DVa", }, headcrab = { sound = "PlayerEnemyOther.DVa", }, manhack = { sound = "PlayerEnemyOther.DVa", }, scanner = { sound = "PlayerEnemyOther.DVa", }, sniper = { sound = "PlayerEnemyOther.DVa", }, turret = { sound = "PlayerEnemyOther.DVa", }, zombie = {}, }, taunt = { [53] = { sound = "PlayerTauntForward.DVa", }, [54] = { sound = "PlayerTauntGroup.DVa", }, [55] = { sound = "PlayerTauntHalt.DVa", }, [1610] = { sound = "PlayerTauntAgree.DVa", }, [1611] = { sound = "PlayerTauntBecon.DVa", }, [1612] = { sound = "PlayerTauntBow.DVa", }, [1613] = { sound = "PlayerTauntDisAgree.DVa", }, [1614] = { sound = "PlayerTauntSalute.DVa", }, [1615] = { sound = "PlayerTauntWave.DVa", }, [1616] = { sound = "PlayerTauntPersistence.DVa", }, [1617] = { sound = "PlayerTauntMuscle.DVa", }, [1618] = { sound = "PlayerTauntLaugh.DVa", }, [1619] = {}, [1620] = { sound = "PlayerTauntCheer.DVa", }, }, } local copy_test = TableFullCopy(test) PrintTable(copy_test) [/code] Result: [code] damage: 0: delay = 0.5 sound = PlayerDamage.DVa 1: delay = 1 sound = PlayerDamageHead.DVa 2: delay = 1 sound = PlayerDamageChest.DVa 3: delay = 1 sound = PlayerDamageChest.DVa 4: delay = 1 sound = PlayerDamageLeftArm.DVa 5: delay = 1 sound = PlayerDamage.DVa 6: delay = 1 sound = PlayerDamageLeftLeg.DVa 7: delay = 1 sound = PlayerDamage.DVa 10: delay = 0.5 sound = PlayerDamage.DVa main: crithealth: delay: 1 = 3.5 2 = 5 sound = PlayerLowHP.DVa crithit: delay: 1 = 3.5 2 = 5 sound = PlayerCritHP.DVa death: sound = PlayerDeath.DVa fall: sound = PlayerFall.DVa heal: sound = PlayerHealed.DVa healmax: sound = PlayerHealedMax.DVa jump: delay = 1 sound = PlayerJump.DVa noammo: sound = PlayerNoAmmo.DVa pickup: sound = PlayerPickUp.DVa reload: delay = 2 sound = PlayerReload.DVa spawn: sound = PlayerSpawn.DVa step: sound = PlayerWalk.DVa murder: ally: delay = 3 sound = PlayerMurder.DVa combine: delay = 3 sound = PlayerMurder.DVa cp: delay = 3 sound = PlayerMurder.DVa generic: delay = 3 sound = PlayerMurder.DVa headcrab: delay = 3 sound = PlayerMurder.DVa manhack: delay = 3 sound = PlayerMurder.DVa scanner: delay = 3 sound = PlayerMurder.DVa sniper: delay = 3 sound = PlayerMurder.DVa turret: delay = 3 sound = PlayerMurder.DVa zombie: delay = 3 sound = PlayerMurder.DVa spot: ally: delay = 2 sound = PlayerAlly.DVa combine: sound = PlayerEnemyOther.DVa cp: sound = PlayerEnemyOther.DVa generic: sound = PlayerEnemyOther.DVa headcrab: sound = PlayerEnemyOther.DVa manhack: sound = PlayerEnemyOther.DVa scanner: sound = PlayerEnemyOther.DVa sniper: sound = PlayerEnemyOther.DVa turret: sound = PlayerEnemyOther.DVa zombie: taunt: 53: sound = PlayerTauntForward.DVa 54: sound = PlayerTauntGroup.DVa 55: sound = PlayerTauntHalt.DVa 1610: sound = PlayerTauntAgree.DVa 1611: sound = PlayerTauntBecon.DVa 1612: sound = PlayerTauntBow.DVa 1613: sound = PlayerTauntDisAgree.DVa 1614: sound = PlayerTauntSalute.DVa 1615: sound = PlayerTauntWave.DVa 1616: sound = PlayerTauntPersistence.DVa 1617: sound = PlayerTauntMuscle.DVa 1618: sound = PlayerTauntLaugh.DVa 1619: 1620: sound = PlayerTauntCheer.DVa [/code] I also [url=http://pastebin.com/5x75auTy]tested it with the model key you provided[/url] and got the [url=http://pastebin.com/tPeaGHse]same working results[/url] which is an exact match to the first PrintTable output in your post.
The issue did turn out to be somewhere else in my code, because I was a dummy and copied table references rather than a table in a few of my modules. Thanks :)
Sorry, you need to
Log In
to post a reply to this thread.