I’m creating a tracking database, gathering information to report for hour, daily, weekly, monthly, yearly, per level, per class, and per tier. As such, I have a table called tracker that consists of a subset of tables, reflecting the different reports (i.e., table["ThisHour"], etc). I’m wondering if there’s a way to consolidate all these lines that really are just adding the same bit of information. Here is the function I’m using, along with just two subtables (instead of the 8 I have listed above):
function exp_update(xp, gold, str, con, dex, wis, int, luck, bpracs, btrains, pracs, trains, qp)
local xtable = tracker[playername]["Exp"]
addto(xtable["ThisHour"],"Exp",xp)
addto(xtable["ThisHour"],"Gold",gold)
addto(xtable["ThisHour"],"BonusStr",str)
addto(xtable["ThisHour"],"BonusCon",con)
addto(xtable["ThisHour"],"BonusDex",dex)
addto(xtable["ThisHour"],"BonusWis",wis)
addto(xtable["ThisHour"],"BonusInt",int)
addto(xtable["ThisHour"],"BonusLuck",luck)
addto(xtable["ThisHour"],"BonusPracs",bpracs)
addto(xtable["ThisHour"],"BonusTrains",btrains)
addto(xtable["ThisHour"],"Pracs",pracs)
addto(xtable["ThisHour"],"Trains",trains)
addto(xtable["ThisHour"],"Qp",qp)
addto(xtable["ThisHour"],"Quests")
addto(xtable["ThisLevel"],"Exp",xp)
addto(xtable["ThisLevel"],"Gold",gold)
addto(xtable["ThisLevel"],"BonusStr",str)
addto(xtable["ThisLevel"],"BonusCon",con)
addto(xtable["ThisLevel"],"BonusDex",dex)
addto(xtable["ThisLevel"],"BonusWis",wis)
addto(xtable["ThisLevel"],"BonusInt",int)
addto(xtable["ThisLevel"],"BonusLuck",luck)
addto(xtable["ThisLevel"],"BonusPracs",bpracs)
addto(xtable["ThisLevel"],"BonusTrains",btrains)
addto(xtable["ThisLevel"],"Pracs",pracs)
addto(xtable["ThisLevel"],"Trains",trains)
addto(xtable["ThisLevel"],"Qp",qp)
addto(xtable["ThisLevel"],"Quests")
end
As you can see, that’s already quite a number of lines for just two subtables. That’s 14 lines of code for each subtable, or, if I put them all in, 112 lines of code that I’d love to consolidate down to as little as possible.
The addto function is as defines, in case you need it:
function addto(t,k,v)
t[k] = t[k] + (v or 1)
end
I’d say to do this: