所以,我在尝试将字符串分成表格(玩家加入团队)时遇到了问题.当只有两个玩家时,它就像一个魅力,但当有3个玩家时,会弹出:“Init Error:transformice.lua:7:bad argument:table expected,no nil”
ps = {"Player1","Player2","Player3","Player4"} local teams={{},{},{}} --[[for name,player in pairs(tfm.get.room.playerList) do table.insert(ps,name) end]] table.sort(ps,function() return math.random()>0.5 end) for i,player in ipairs(ps) do table.insert(teams[i%#teams],player) endLua数组从索引1开始,而不是0.如果你有3个玩家,那么这一行:
table.insert(teams[i%#teams],player)
评估为:
table.insert(teams[3%3],player)
那将最终成为:
table.insert(teams[0],player)
而团队[0]将是零.你应该能够把它写成:
table.insert(teams[i%#teams+1],player)
代替.