Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基本Lua问题-嵌套在for循环中的if语句_Lua - Fatal编程技术网

基本Lua问题-嵌套在for循环中的if语句

基本Lua问题-嵌套在for循环中的if语句,lua,Lua,我是Lua的业余爱好者,我写了这段代码,但编译失败,我检查了语法结构,发现它是匹配的,所以我真的不知道是什么错了,它说 18.“起始点”附近的“结束点”(第16行的“如果”关闭) 但我为什么要这么做????? 顺便说一句,startFishing是我以前在同一个文件中定义的另一个函数 function detectSuccess() local count = 0; for x = 448, 1140, 140 do color = getColor(x, 170

我是Lua的业余爱好者,我写了这段代码,但编译失败,我检查了语法结构,发现它是匹配的,所以我真的不知道是什么错了,它说 18.“起始点”附近的“结束点”(第16行的“如果”关闭) 但我为什么要这么做????? 顺便说一句,startFishing是我以前在同一个文件中定义的另一个函数

function detectSuccess()
    local count = 0;
    for x = 448, 1140, 140 do
        color = getColor(x, 170);
        if color == 0xffffff then 
            return false
            startFishing()
        else
            return true
        end
    end
end

返回之后,同一块中不能有语句。我想你的意思是:

if color == 0xffffff then 
   startFishing()
   return false
else
   return true
end

缩进代码将有助于查看语法问题。

返回后,同一块中不能有语句。我想你的意思是:

if color == 0xffffff then 
   startFishing()
   return false
else
   return true
end

缩进代码将帮助您看到语法问题。

正确格式化代码我们有

function detectSuccess()
   local count = 0;
    for x = 448, 1140, 140 do
        color = getColor(x, 170);
        if color == 0xffffff then 
            return false
            startFishing()
        else
            return true
        end
    end
end

detectSuccess()
startFishing()
语句悬空。从语法上讲,返回之后唯一可以出现的东西是else或end

这就是lua解析器的抱怨

出于语法原因,break或return只能作为块的最后一条语句出现(换句话说,作为块中的最后一条语句,或者正好在end、else或until之前)

如果要调用
startFishing
,则必须在返回之前调用。e、 g

function detectSuccess()
   local count = 0;
    for x = 448, 1140, 140 do
        color = getColor(x, 170);
        if color == 0xffffff then 
            startFishing() -- moved before the return
            return false
        else
            return true
        end
    end
end

正确格式化代码我们有

function detectSuccess()
   local count = 0;
    for x = 448, 1140, 140 do
        color = getColor(x, 170);
        if color == 0xffffff then 
            return false
            startFishing()
        else
            return true
        end
    end
end

detectSuccess()
startFishing()
语句悬空。从语法上讲,返回之后唯一可以出现的东西是else或end

这就是lua解析器的抱怨

出于语法原因,break或return只能作为块的最后一条语句出现(换句话说,作为块中的最后一条语句,或者正好在end、else或until之前)

如果要调用
startFishing
,则必须在返回之前调用。e、 g

function detectSuccess()
   local count = 0;
    for x = 448, 1140, 140 do
        color = getColor(x, 170);
        if color == 0xffffff then 
            startFishing() -- moved before the return
            return false
        else
            return true
        end
    end
end
startFishing()
after
return
startFishing()
after
return
??