I've been scratching my head all morning trying to figure out where I'm going wrong with this bit of code. Basically, I'm borrowing the idea from Ked to use GetInfo(232) as a method of expiring balances in a failsafe. (I'm sure my logic is confused in my scripts overall, but that's a separate issue.)
Here's what I'm using for my metatable, and I'm not seeing the expected values and notes when I set/get things. Any ideas?
Here's what I'm using for my metatable, and I'm not seeing the expected values and notes when I set/get things. Any ideas?
lost_bals = {}
setmetatable(lost_bals,
{
__index =
function (t, name)
local b = rawget(t, name)
Note("Table " .. tostring(t) .. ", key " .. name .. " has value " .. tostring(b))
if (not b) then
return false
end
if (b <= GetInfo(232)) then
t[name] = nil
return false
end
return true
end,
__newindex =
function(t, name, val)
if (val == nil) then
Note("Table " .. tostring(t) .. ", key " .. name .. " deleted")
rawset(t, name, nil)
return
end
local v = (val or 5.0) + GetInfo(232)
Note("Table " .. tostring(t) .. ", key " .. name .. " gets value " .. tostring(v))
rawset(t, name, v)
end
})