对不起,我还在学习 lua。你能纠正我吗,为什么文件中的数据不会逐行读取?
这是我在文件points.txt中的示例数据:
lexxo:30:1
rey:40:2
lion:40:2
prince:50:3
royal:50:3
所以当我从上面得到的是二维数组(表)
player = {{(name),(points),(which var point earned on index)},
{(...),(...),(...)}};
所以问题是,当我尝试循环打印文件中的所有数据时。它只打印最后一行。所以我想要打印所有这些
line_points = {}
player_data = {{}}
local rfile = io.open("points.txt", "r")
for line in rfile:lines() do
playername, playerpoint, playeridpoint = line:match("^(.-):(%d+):(%d+)$")
player_data = {{playername, playerpoint, playeridpoint}}
line_points[#line_points + 1] = player_data
end
for i = 1, #player_data do
player_checkname = player_data[i][1] -- Get Player Name From Array for checking further
player_checkpnt = player_data[i][3] -- Get Player ID Point From Array for checking further
print(i..". Name: "..player_data[i][1].." Point: ".. player_data[i][2] .. " ID: " .. player_data[i][3]);
end