我以前從未使用過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