【发布时间】:2017-02-24 03:44:41
【问题描述】:
我以前从未使用过 corona sdk,因此决定创建一个键盘记录器来测试我是否喜欢 corona。
我可以检查输入并指定文件路径,但是一旦我的代码到达 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)
【问题讨论】:
-
io.open(path, "W")"W" 应为小写 -
我已经设法弄清楚了,但感谢您的评论。