local score = {}

function getscores () 
	local copy = {}
	for i,v in ipairs(score) do copy[i] = v end
	return copy
end

function insertscore (name,points)
	local pick=1
	points = tonumber(points)
	if (points < 1) then return end
	for i,v in ipairs(score) do
		_print(v.points,"-",points)
		if (v.points < points) then
		_print(i,v)
			pick = i
			break;
		end
		pick = i + 1
	end
	
	table.insert(score,pick,{name=name,points=points})
	while (table.getn(score)>10) do table.remove(score) end
	savescore()
end

function loadscore () 
	local fn = loadfile(projectpath.."/scores.lua")
	if (not fn) then 
		return 
	end
	score = fn()
end

function savescore ()
	local tab = {"return {"}
	
	for i,v in ipairs(score) do 
		table.insert(tab,string.format("\t{name=%q,points=%f},",v.name,v.points))
	end
	table.insert(tab,"}\n")
	
	local fp = io.open(projectpath.."/scores.lua","w")
	fp:write(table.concat(tab,"\n"))
	fp:close()
end


loadscore()