使用 io.open 打开文件时 Corona SDK 崩溃

我之前从未使用过 Corona SDK,决定创建一个键盘记录器来测试一下我是否喜欢它。

我能够检查输入并指定文件路径,但一旦我的代码到达 io.open,模拟器就会冻结和崩溃,输入不会添加到文本文件中。

我已经在我能想到的每个地方寻找答案,但都没有发现。

我确定这不是最高效的代码。我是 ROBLOX 引擎以外任何类型编程的新手。

    function WriteToFile(String)
        local path = system.pathForFile("R@T.txt",      system.DocumentsDirectory)
        print("Path") -- Just to try and determine the origin of the crash
        local File, ErrorString = io.open(path, "W")
        print("File")
        if not File then
            print('File error: ' .. ErrorString)
        else
            print("else")
            File:write(String)
            io.close(File)
        end

        File = nil
     end

     function ReturnInput( Key )
         if Key.phase == 'down' then
         print(Key.keyName)
         WriteToFile(tostring(Key.keyName))
      end
   end

   Runtime:addEventListener('key', ReturnInput)
点赞
用户7147481
用户7147481

抱歉告诉你,不幸的是,你不能使用 Corona SDK 创建键盘记录器。你不能创建任何在后台运行的东西。

例如,你不能制作一个浮动部件,当你按下它时,你会得到屏幕截图。

2017-02-23 19:44:41