2013-07-25 67 views
0

我對Lua一無所知,但我能夠修改我想要的腳本。儘管我在排序表中遇到麻煩。Lua排序表

我發現桌子utils的(表格轉換成字符串),
這裏是我的表:

{{line="(Golden Aura) Challenging An owl would be either very brave or very stupid.",range="(+16 to +21)",message="(Golden Aura) Challenging An owl would be either very brave or very stupid.",colour="crimson",srt=9,keyword="owl",name="An owl"}, 
{line="(Golden Aura) A busy squirrel chuckles at the thought of you fighting him.",range="(+3 to +8)",message="(Golden Aura) A busy squirrel chuckles at the thought of you fighting him.",colour="gold",srt=7,keyword="squirrel",name="(Golden Aura) A busy squirrel"}, 
{line="(Red Aura) A parakeet should be a fair fight!",range="(-2 to +2)",message="(Red Aura) A parakeet should be a fair fight!",colour="springgreen",srt=5,keyword="parakeet",name="(Red Aura) A parakeet"}, 
{line="(Golden Aura) Challenging A cat would be either very brave or very stupid.",range="(+16 to +21)",message="(Golden Aura) Challenging A cat would be either very brave or very stupid.",colour="crimson",srt=9,keyword="cat",name="A cat"}} 

我能夠添加SRT關鍵,我想通過排序表。請有人告訴我該怎麼做?

回答

3
table.sort(table:t [, function(left, right):sorting function ]) 

所以,既然你想通過v.srt進行排序,你會做這樣的事情:

table.sort(t, function(a, b) return a.srt < b.srt end) 

for k, v in pairs(t) do 
    print(v.srt, v.name) 
end 

應在升序進行排序,然後顯示出來。

+0

謝謝!現在我知道自己做錯了什麼,我用了[srt]和b [srt] :) – user2618401

+1

@ user2618401你可能一直在想'a [「srt」]'這與'a.srt'相同。 –