如何在排行榜中保存字符串?(Corona SDK)

我在处理我的排行榜时遇到了问题,问题在于我的数组得分都按升序排列,这很好,但我无法保存得分旁边的文本?情况是game.lua -> gameOver(得分和难度文本) -> leaderboards(得分)。从表中调用变量无效。

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

点赞
用户7026995
用户7026995

如果你的 leaderboard 是一个只有分数的表格,像这样

leaderboard = { 100, 200, 300 }

并且你也想在其中加入字符串(难度等级)与分数。可以这样做

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

访问 leaderboard 的元素

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

排序表

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

table.sort(leaderboard, compare)
2017-01-15 11:02:37