I make some effort to preserve order, but deleting results and then readding them appends to the bottom.
V5CVWVALAROQHZ23WC2KISEIHIYD3JEALPQ7P2T7KPOZPIJNGOMAC
T2DONXNWMEH4N5S7DVHKA35AHRXWRH3OBFQRS6Z5BHIRVKA5IGJAC
UOVX4WJLIAMFNDXXDVZYGS2RCTJYXV2NMKITXN3E3DH7BP5D32DAC
R5QXEHUIZLELJGGCZAE7ATNS3CLRJ7JFRENMGH4XXH24C5WABZDQC
6RN2M65LZLKSK3DJN4TAMLSDRZ3SG7OFDIPQXIYEC66WLII2IBNAC
NBRFAEJR4UBMKQ7NSMMDFKVDP7UVIIBQZORVQAPK2W4VFQBVJVKQC
S5ADH7USXGZCRISF5TQOAST7RQQ2EUX5QVLFMGVTWTS65KFOO7MAC
delete_result = function(from, to)
for i=1,#Global_state.results do
if eq(Global_state.results[i], {from, to}) then
table.remove(Global_state.results, i)
end
end
end
add_result = function(from, to)
table.insert(Global_state.results, {from, to})
end
on.quit = function()
if Global_state.next_save then
save_results()
Global_state.next_save = nil
end
end
save_results = function()
if Results_filename == nil then return end
print('saving to '..Results_filename)
local f, err = App.open_for_writing(Results_filename)
if err then error(err) end
for _,result in ipairs(Global_state.results) do
f:write(('%s beat %s\n'):format(result[1], result[2]))
end
f:close()
end
on.update = function()
if Global_state.next_save and Global_state.next_save < Current_time then
save_results()
Global_state.next_save = nil
end
end
Global_state = {} -- just anything we need across functions
-- just anything we need across functions
Global_state = {
button_handlers = {},
next_save = nil, -- if set, timestamp at which to save results to disk
results = {}, -- information about order in which to save to disk
}