我以前从未使用过corona sdk,并决定创建一个密钥记录器作为测试以查看我是否喜欢corona。corona sdk在尝试使用io.open打开文件时崩溃
我能够检查输入并指定文件路径,但是一旦我的代码到达io.open,模拟器将冻结并崩溃,并且输入不会添加到文本文件中。
我已经看过几乎所有我能想到的答案,但没有找到答案。
我相信这不是最有效的代码。我是ROBLOX引擎以外的任何类型编程的新手。
function WriteToFile(String)
local path = system.pathForFile("[email protected]", 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“应该是小写的 –
我设法弄清楚了这一点,但感谢评论。 – AZDev