1
Talk guys, I’m trying to record some information on a . json but I’m getting this error:
date.lua:12: Attempt to index local 'rkgdat' (a nil value)
local triggers = {
''
}
local action = function(msg)
local rkgdat = load_data('data/ranking/' .. msg.chat.id .. '.json')
if not rkgdat[msg.from.id] then
rkgdat[msg.from.id] = {
['primeiro_nome'] = msg.from.first_name .. ' (' .. msg.from.id .. ')',
['mensagens'] = 1
}
save_data('data/ranking/' .. msg.chat.id .. '.json', rkgdat)
else
rkgdat[msg.from.id] = {
['primeiro_nome'] = msg.from.first_name .. ' (' .. msg.from.id .. ')',
['mensagens'] = rkgdat[msg.from.id]['mensagens'] + 1
}
save_data('data/ranking/' .. msg.chat.id .. '.json', rkgdat)
end
return true
end
return {
action = action,
triggers = triggers,
}
Function loaded from another file
load_data = function(filename)
local f = io.open(filename)
if not f then
return {}
end
local s = f:read('*all')
f:close()
local data = JSON.decode(s)
return data
end
save_data = function(filename, data)
local s = JSON.encode(data)
local f = io.open(filename, 'w')
if file==nil then
print("Couldn't open file: "..f)
else
f:write(s)
f:close()
end
end
https://core.telegram.org/bots/api http://www.lua.org/pil/21.2.html
Opa valeu friend, Solved !
– Santagain