Lua(Corona SDK)Android问题-间隔为空

在计算机上,我的游戏可以顺利编译并正常运行,但是一旦我为Android构建它,我就会得到这个奇怪的错误代码:

bad argument #1 to 'random' (interval is empty)

这个错误代码来自以下代码行:

local word = wordsList[math.random(#wordsList)]

整个代码片段如下:

local lineCount = 1
local wordsList = {}
local wordAccepted = true
local file = io.open( system.pathForFile( "words.txt", system.ResourceDirectory ), "r" ) --从资源文件夹打开单词文件
for line in file:lines() do
    if #line > 1 and #line <= 10 then
        for i = 1,#line do
            if string.byte(line,i)<65 or string.byte(line,i)>90 and string.byte(line,i)<97 or string.byte(line,i)>122 then
                wordAccepted = false
            end
        end
        if wordAccepted == true then
            print ("accepted "..line)
            wordsList[lineCount]=string.upper(line)
            lineCount = lineCount + 1
        else
            print("rejected "..line)
        end
    end
end
io.close( file )
file = nil
local word = wordsList[math.random(#wordsList)]
点赞
用户1847592
用户1847592

错误信息 bad argument #1 to 'random' (interval is empty) 表示你正试图向 math.random() 传递零。

换句话说,你的 wordsList 数组为空。

2015-04-22 10:02:38