I'm trying to make an xp tracker that tracks the last hour's experience gained and this is what I have thus far:
But when running showxp it gives me the error message
Which seems to me that it's saying either the table isn't saving after the newrecord function runs or there's some other way to access tables that aren't created by the executing function. What am I doing wrong here? Thanks
function newrecord (name, line, wildcards)
if tracking == nil then
tracking = {}
end -- if
record = {}
record.xp = wildcards [1]
record.time = os.time()
table.insert(tracking, record)
end -- function
function showxp (name, line, wildcards)
xphour = 0
while next(tracking) ~= nil do
record = tracking[1]
print (record.time)
if record.time < os.time() - 3600 then
table.remove(tracking, 1)
else -- Everything after is newer
xphour = xphour + record.xp
end -- if
end -- while
print ("Experience gained this hour: " .. xphour)
end --function
But when running showxp it gives me the error message
Run-time error
World: Aardwolf
Function/Sub: showxp called by alias
Reason: processing alias ""
[string "Script file"]:15: bad argument #1 to 'next' (table expected, got nil)
stack traceback:
[C]: in function 'next'
[string "Script file"]:15: in function <[string "Script file"]:13>
Error context in script:
11 : end -- function
12 :
13 : function showxp (name, line, wildcards)
14 : xphour = 0
15*: while next(tracking) ~= nil do
16 : record = tracking[1]
17 : print (record.time)
18 : if record.time < os.time() - 3600 then
19 : table.remove(tracking, 1)
Which seems to me that it's saying either the table isn't saving after the newrecord function runs or there's some other way to access tables that aren't created by the executing function. What am I doing wrong here? Thanks