I'm pretty sure my subject was quite vague, but due to the limits, I tried to explain what the situation is.
I'm running a tracking script to keep track of my gains throughout levels. It's another script I've been converting over from CMUD, and really is my pride and joy. Since I wanted to save all the information over time (and not really partial to CMUD's own zscript variables), I saved the tables to a .tbl file, which I could load up at any given time. This is akin to the serialize.save function you have.
Here's where my issue lies:
The whole of the database is called: trackerdb. Within trackerdb, there are top-level keys based on player name (useful for keeping track of individual alts progress). So, for instance, I would have a table of trackerdb["Charneus"], which has all of Charneus's stats, and trackerdb["Calamer"], which has all of Calamer's stats.
I can't seem to replicate this in MUSH, however, using serialize and setfenv. Due to the length of code, I'm going to just provide snippets so you can get the general idea.
What the serialized variable contains:
What the trackerdb should serialize as after a new player has been initiated:
Unfortunately, all I wind up getting is a super mess. The code I'm attempting to use is:
So, is there an easy way to pull this off? Thanks!
I'm running a tracking script to keep track of my gains throughout levels. It's another script I've been converting over from CMUD, and really is my pride and joy. Since I wanted to save all the information over time (and not really partial to CMUD's own zscript variables), I saved the tables to a .tbl file, which I could load up at any given time. This is akin to the serialize.save function you have.
Here's where my issue lies:
The whole of the database is called: trackerdb. Within trackerdb, there are top-level keys based on player name (useful for keeping track of individual alts progress). So, for instance, I would have a table of trackerdb["Charneus"], which has all of Charneus's stats, and trackerdb["Calamer"], which has all of Calamer's stats.
I can't seem to replicate this in MUSH, however, using serialize and setfenv. Due to the length of code, I'm going to just provide snippets so you can get the general idea.
What the serialized variable contains:
ReportChan = "gt"
Quests = {}
Quests.LastQuest = {}
Quests.LastQuest.Pracs = 0
Quests.LastQuest.Qp = 0
Quests.LastQuest.Gold = 0
Quests.LastQuest.Trivia = 0
Quests.LastQuest.Trains = 0
Quests.Total = {}
Quests.Total.Pracs = 0
Quests.Total.Trains = 0
Quests.Total.Qp = 0
Quests.Total.Completed = 0
Quests.Total.Gold = 0
Quests.Total.Failed = 0
Quests.Total.BonusQp = 0
Quests.Total.Trivia = 0
Quests.Report = ""What the trackerdb should serialize as after a new player has been initiated:
trackerdb = {}
trackerdb.Charneus = {}
trackerdb.Charneus.ReportChan = "gt"
trackerdb.Charneus.Quests = {}
trackerdb.Charneus.Quests.LastQuest = {}
trackerdb.Charneus.Quests.LastQuest.Pracs = 0
trackerdb.Charneus.Quests.LastQuest.Qp = 0
trackerdb.Charneus.Quests.LastQuest.Gold = 0
trackerdb.Charneus.Quests.LastQuest.Trivia = 0
trackerdb.Charneus.Quests.LastQuest.Trains = 0
trackerdb.Charneus.Quests.Total = {}
trackerdb.Charneus.Quests.Total.Pracs = 0
trackerdb.Charneus.Quests.Total.Trains = 0
trackerdb.Charneus.Quests.Total.Qp = 0
trackerdb.Charneus.Quests.Total.Completed = 0
trackerdb.Charneus.Quests.Total.Gold = 0
trackerdb.Charneus.Quests.Total.Failed = 0
trackerdb.Charneus.Quests.Total.BonusQp = 0
trackerdb.Charneus.Quests.Total.Trivia = 0
trackerdb.Charneus.Quests.Report = ""Unfortunately, all I wind up getting is a super mess. The code I'm attempting to use is:
function init_tracker(pname, reset)
-- trackertemplate = {} -- original code
trackerdb[pname] = {} -- second try
setfenv (assert( loadstring( GetVariable("trackerdbtemplate"))), trackerdb[pname]) () -- trackerdb[pname] was trackertemplate on original code
--trackerdb[pname]=trackertemplate -- original code
local ttable = trackerdb[pname]
local resettime = socket.gettime()
for k,_ in pairs(ttable["Timers"]) do
ttable["Timers"][k]["Start"] = resettime
end
ttable["HasPupped"]=0
if reset then print(pname,"has been reset!")
else
print(pname,"has been initialized!")
end
SetVariable("trackerdb", serialize.save("trackerdb"))
endSo, is there an easy way to pull this off? Thanks!