在android设备上安装并运行我的应用程序后,当我点击highscore它应该发布“highscore:0”如果它是第一次运行我的问题的应用程序是这个代码
local path = system.pathForFile( "myfile.txt", system.DocumentsDirectory )
似乎android设备中没有system.DocumentsDirectory我需要在编写之前创建文本文件拳头问题是我的路径我需要它来创建myfile.text那么什么可以替代system.DocumentsDirectory?我不能使用 system.ResourceDirectory 导致它的唯一可读不可写
这是我的 highscore.lua,如果用户在安装后玩游戏之前检查高分 1st
local path = system.pathForFile( "myfile.txt", system.DocumentsDirectory )
local file = io.open( path, "r" )
local savedData = file:read( "*n" )
if (savedData == nil) then
file=io.open(path,"w")
local newVal="0"
file:write(newVal)
file:flush()
local scoreText = display.newText("score: " .. newVal, 0, 0, "BorisBlackBloxx", 50)
scoreText:setReferencePoint(display.CenterLeftReferencePoint)
scoreText.x = 0
scoreText.y = 30
else
local scoreText = display.newText("score: " .. savedData, 0, 0, "BorisBlackBloxx", 50)
scoreText:setReferencePoint(display.CenterLeftReferencePoint)
scoreText.x = 0
scoreText.y = 30
end
如果用户第一次玩游戏,这对于我的 game.lua 使用它
local path = system.pathForFile( "myfile.txt", system.DocumentsDirectory )
local reader = io.open( path, "r" )
local contents = reader:read("*n")
local file = io.open( path, "w" )
if (contents == nil) then
local walaVal="0"
file:write(walaVal)
file:flush()
else
file:write(contents)
file:flush()
end