【问题标题】:Array returns different LUA数组返回不同的 LUA
【发布时间】:2013-04-15 16:55:42
【问题描述】:

我的阵列有问题。我最初在其中放置了一些值,但是当我尝试通过创建另一个打印值的循环来显示数组的内容时,它只显示数字“1”作为内容。谁能指出错误?这是一个与我的代码有同样困境的代码。

local input = {} 

for line in io.lines 'try.txt' do
    for i =0,2 do
        column = 0
        for n in line:gmatch'%S+' do
            input[column] = 1
            column = column + 1
            if column < 11 then
                input[column] = tonumber(n)
                print("input",input[column],column)
            end
        end
    end

    print("\n")    

    for k = 0, 10 do
        print("-->",input[k],k)
    end

end

我的 'try.txt' 只包含 ff。

2 64 124 21.282 128 91 18 97.8 0 0 0 
2 -99 0 0 161 69 -99 97.7 0 0 0 
1 68 195 29.646 162 87 20 98 0 0 0 

【问题讨论】:

    标签: arrays lua


    【解决方案1】:

    交换这些行:

    input[column] = 1
    column = column + 1
    

    【讨论】:

      猜你喜欢
      • 2019-06-17
      • 2015-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-12
      • 1970-01-01
      • 2016-11-19
      • 2012-12-08
      相关资源
      最近更新 更多