hello i need to sort thé lise by value not by ligne num
How can i do so?
function setup()
displayMode(FULLSCREEN)
clearLocalData()
liste=listLocalData()
-- creer une liste vide
if #liste==0 then
for i=1,10 do
str=string.format("%2d",i)
saveLocalData(str,math.random(1,300))
end
liste=listLocalData()
end
end
function draw()
background(39, 40, 50, 255)
font("AmericanTypewriter")
fill(255, 0, 169, 255)
fontSize(30)
textMode(CORNER)
text("num ligne# score",40,750-50)
for num,ligne in ipairs(liste) do
score=readLocalData(ligne)
text(num.." "..ligne.." "..score,40,700-50*num)
end
end
function ordre(a, b)
return a<= b
end
function touched(touch)
if CurrentTouch.state==BEGAN then
table.sort(liste,ordre)
end
end
function setup()
displayMode(FULLSCREEN)
clearLocalData()
liste=listLocalData()
-- creer une liste vide
if #liste==0 then
for i=1,10 do
str=string.format("%2d",i)
saveLocalData(str,math.random(1,300))
end
liste=listLocalData()
end
-- create table with scores and ligne#
scores={}
for num,ligne in pairs(liste) do
table.insert(scores,{readLocalData(ligne),ligne})
end
end
function draw()
background(39, 40, 50, 255)
font("AmericanTypewriter")
fill(255, 0, 169, 255)
fontSize(30)
textMode(CORNER)
text("num ligne# score",40,750-50)
for num,ligne in ipairs(scores) do
text(num.." "..ligne[2].." "..ligne[1],40,700-50*num)
end
end
function touched(touch)
if CurrentTouch.state==BEGAN then
table.sort(scores,function(a,b) return(a[1]>b[1]) end)
end
end