Sort by value

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

table.sort(liste,function(a,b) return liste[a]<liste[b] end)

For more info, Google for sort table lua

@franck Try this.


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

@franck Here’s something I wrote back in Sept 2013. You might be able to use it.

http://codea.io/talk/discussion/3676/high-score-class#latest

Thank i was loocking for the information since 3 days
You make m’y day