【发布时间】:2021-06-27 09:57:21
【问题描述】:
我一直在整理一些代码来对人们的考试分数进行排序,这样他们就可以看到他们的最高分数是多少以及他们何时完成的。我创建了以下代码,但它没有显示第 1、第 2、第 3 等计数器,我错过了什么?
local tt ={}
local verbalreasoning = {
{ test=1, name="Ben", res=12, testdate="June 20" },
{ test=2, name="Ben", res=12, testdate="June 21" },
{ test=3, name="Ben", res=12, testdate="June 22" },
{ test=4, name="Ben", res=14, testdate="June 23" },
{ test=5, name="Ben", res=12, testdate="June 24" },
{ test=6, name="Ben", res=17, testdate="June 25" },
{ test=7, name="Ben", res=16, testdate="June 26" },
{ test=8, name="Ben", res=12, testdate="June 27" }
}
for _, v in ipairs(verbalreasoning) do
table.insert(tt, { myres=v.res, myname=v.name, mydate=v.testdate })
end
table.sort(tt, function(a,b) return a.myres > b.myres end) -- sort highest to lowest
local count = 0
local increment = 1
for _,v in pairs(tt) do
local count = count + increment
print(count, v.myres, v.myname, v.testdate)
end
它打印以下内容,所有内容都显示为 1,什么时候应该是 1、2、3 等等。
1 17 Ben
1 16 Ben
1 14 Ben
1 12 Ben
1 12 Ben
1 12 Ben
1 12 Ben
1 12 Ben
【问题讨论】:
标签: lua