当我在corona中输入我的updateScore函数时出现错误。

我遇到了错误,这是链接:http://cdn.imghack.se/images/b902d2e1eea1f477e1a649f6004f34f3.png,我正在使用 director 类,在我的代码中,当我写下以下内容时出错:

        local path = system.pathForFile( "myfile.txt", system.DocumentsDirectory )
        local file = io.open( path, "w+" )
        local reader, er = io.open( path, "r" )
        local contents = reader:read("*n")

                local function update( event )
                updateBackgrounds()
                updateSpeed()
                updateMonster()
                updateBlocks()
                updateBlasts()
                updateSpikes()
                updateGhosts()
                checkCollisions()
                updateScore()
                end

            function updateScore()

                        if (stopscore == false) then
                                score = score + 1
                                scoreText.text = "score: " .. score
                                scoreText:setReferencePoint(display.CenterLeftReferencePoint)
                                scoreText.x = 0
                                scoreText.y = 30
                                print (er)
                        else
                                if(  contents == nil ) then
                                        file:write(score)
                                        file:close()
                                        reader:close()

                                else
                                        file:close()
                                        reader:close()
                                end

                                 if ( contents < score and monster.isAlive == false)
                                        file:write(score)
                                        file:close()
                                        reader:close()
                                else
                                        file:close()
                                        reader:close()
                                end

                        end
             end

有人可以帮帮我吗?我还是遇到了相同的错误。

点赞
用户2186639
用户2186639

你有一个语法错误,检查下面的代码:

   function updateScore()

        if (stopscore == false) then
            score = score + 1
            scoreText.text = "score: " .. score
            scoreText:setReferencePoint(display.CenterLeftReferencePoint)
            scoreText.x = 0
            scoreText.y = 30
        else
            if( contents < score and monster.isAlive == false) then
                file:write(score)
                file:close()
                reader:close()
            else
                file:close()
                reader:close()
            end
        end
    end
2013-07-22 14:21:59