tsuujin wrote:as long as the keys are populated, it should just be a simple issue of echoing it out.
arr["another"]["test"]["of"]["arrays"] = "This is the resulting echo"
echo(arr["another"]["test"]["of"]["arrays"])
If you're having problems with it, the first step is to simply check for existence with an if statement
if arr["another"]["test"]["of"]["arrays"] then
echo("Yep.")
else
echo("Nope.")
end
Thanks, Tsuujin.
I did that, and it echos as "Yep."
When I try to do the following script:
Code: Select all
for attackers, damTargets in pairs (battle_data) do
for victims, nouns in pairs (damTargets) do
for nountypes, info in pairs (nouns) do
for infotypes,values in pairs (info) do
echo(tostring(attackers))
echo(tostring(victims))
echo(tostring(nountypes))
echo(tostring(infotypes))
echo(tostring(values))
--echo(# infotypes)
echo(tostring(battle_data[tostring(attackers)][tostring(victims)][tostring(nountypes)][tostring(infotypes)]).."\n")
end
end
end
end
the output is the following:
Youra lizardchop missestable: 0x7fd64e0table: 0x7fd64e0
Youra lizardchop hitstable: 0x7f9ab30table: 0x7f9ab30
So it's generating a table for
battle_data[tostring(attackers)][tostring(victims)][tostring(nountypes)][tostring(infotypes)]
that is equal to what it reports if I do echo(tostring(values))
but when I try to add another "for" loop to unpack the values table, then it breaks the script when I try to echo the resulting keys. I use the following code:
Code: Select all
for attackers, damTargets in pairs (battle_data) do
for victims, nouns in pairs (damTargets) do
for nountypes, info in pairs (nouns) do
for infotypes,values in pairs (info) do
for k, v in pairs (values) do
echo(tostring(attackers))
echo(tostring(victims))
echo(tostring(nountypes))
echo(tostring(infotypes))
echo(tostring(values))
--echo(# infotypes)
echo(tostring(battle_data[tostring(attackers)][tostring(victims)][tostring(nountypes)][tostring(infotypes)]).."\n")
echo(tostring(v))
end
end
end
end
end
I just added the for loop and the echo(tostring(v)) and there is no output.
I also replace v with k, and there is no output. I delete this echo line altogether, so only the for loop is left, and the script doesn't work. So the for loop must be breaking it.
The way I am populating the battle_data dictionary is with the following script (after some code to generate all the keys, which I know are working fine because I can echo them using the above code):
Code: Select all
if battle_data == nil then
battle_data = battle_data or {}
battle_data[attacker]=battle_data[attacker] or {}
battle_data[attacker][damTarget]=battle_data[attacker][damTarget] or {}
battle_data[attacker][damTarget][noun]=battle_data[attacker][damTarget][noun] or {}
battle_data[attacker][damTarget][noun]["hits"]=battle_data[attacker][damTarget][noun]["hits"] or {}
battle_data[attacker][damTarget][noun]["misses"]=battle_data[attacker][damTarget][noun]["misses"] or {}
battle_data[attacker][damTarget][noun]["total_hits"]=battle_data[attacker][damTarget][noun]["total_hits"] or {}
battle_data[attacker][damTarget][noun]["dam"] = battle_data[attacker][damTarget][noun]["dam"] or {}
battle_data[attacker]["you"] = battle_data[attacker]["you"] or {}
battle_data[attacker]["you"]["evaded"] = battle_data[attacker]["you"]["evaded"] or {}
battle_data[attacker]["you"]["evaded"]["misses"] = battle_data[attacker]["you"]["evaded"]["misses"] or {}
battle_data["You"] = battle_data["You"] or {}
battle_data["You"][damTarget] = battle_data["You"][damTarget] or {}
battle_data["You"][damTarget]["evaded"] = battle_data["You"][damTarget]["evaded"] or {}
battle_data["You"][damTarget]["evaded"]["total_hits"] = battle_data["You"][damTarget]["evaded"]["total_hits"] or {}
battle_data[attacker][damTarget][noun]["<gold>s<white>"] = battle_data[attacker][damTarget][noun]["<gold>s<white>"] or {}
battle_data[attacker][damTarget][noun]["<red>f<white>"] = battle_data[attacker][damTarget][noun]["<red>f<white>"] or {}
battle_data[attacker][damTarget][noun]["<cornsilk>h<white>"] = battle_data[attacker][damTarget][noun]["<cornsilk>h<white>"] or {}
battle_data[attacker][damTarget][noun]["<deep_pink>m<white>"] = battle_data[attacker][damTarget][noun]["<deep_pink>m<white>"] or {}
battle_data[attacker][damTarget][noun]["<dark_orchid>S<white>"] = battle_data[attacker][damTarget][noun]["<dark_orchid>S<white>"] or {}
battle_data[attacker][damTarget][noun]["<powder_blue>f<white>"] = battle_data[attacker][damTarget][noun]["<powder_blue>f<white>"] or {}
end
if damAssign > 0 then
battle_data[attacker][damTarget][noun]["hits"]= (battle_data[attacker][damTarget][noun]["hits"] or 0) +1
else
battle_data[attacker][damTarget][noun]["misses"] = (battle_data[attacker][damTarget][noun]["misses"] or 0) +1
end --if
battle_data[attacker][damTarget][noun]["total_hits"] = (battle_data[attacker][damTarget][noun]["total_hits"] or 0) + 1
battle_data[attacker][damTarget][noun]["dam"] = (battle_data[attacker][damTarget][noun]["dam"] or 0) + damAssign
I have some more code to populate the other categories (like the [powder_blue]f and stuff) but I'm just showing an example here because it's more of the same for that but with different trigger conditions.
Am I doing something wrong in assigning my values?
For some reason I can't seem to echo the numbers they equal.
Thanks!
edit: I should note that I also tried "tonumber" instead of "tostring" for
Code: Select all
echo(tonumber(values))
echo(tonumber(battle_data[tostring(attackers)][tostring(victims)][tostring(nountypes)][tostring(infotypes)]).."\n")
But it breaks the script at that line too (and echos everything prior to it)