-1

I'm having a problem with my leaderboards, the problem is my array score are all sorted in ascending order and works fine but I can't save the text beside the score? The situation is game.lua --> gameOver(Score & Difficulty Text) --> leaderboards(Score). Calling the variable from a table doesn't work.

leaderboards.lua

for i = 1, 10 do
    if (scoresTable[i]) then
      local yPos = 150 + (i * 130)

      local thisScore = display.newText(sceneGroup, scoresTable[i].. options.title,display.contentCenterX-30, yPos, font, 100)
      thisScore.anchorX = 0

    end
  end

game.lua

options{
  title = "Easy",
}

gameover.lua

options{
   title = options.title,
}

enter image description here

Kilik Sky
  • 151
  • 1
  • 1
  • 12

1 Answers1

0

If your leaderboard is table with only scores like that

leaderboard = { 100, 200, 300 }

and you want also put string (difficulty level) in it along score. It can be done like that

leaderboard = { {100, "Easy"}, {200, "Hard"}, {300, "Easy"} }

Access to elements of leaderboard

leaderboard[1]     -> {100, "Easy"}
leaderboard[1][1]  -> 100
leaderboard[1][2]  -> "Easy"

Sorting table

function compare(a,b)
  return a[1] < b[1]
end

table.sort(leaderboard, compare)
ldurniat
  • 1,687
  • 2
  • 9
  • 16