私のアプリをAndroidデバイスにインストールして実行した後、ハイスコアをクリックすると、私の問題を初めて実行するアプリがこのコードである場合、「ハイスコア:0」が投稿されるはずです
local path = system.pathForFile( "myfile.txt", system.DocumentsDirectory )
Androidデバイスにsystem.DocumentsDirectoryがないようです問題を書く前にテキストファイルの拳を作成する必要があります私のパスはmyfile.textを作成するために必要なので、system.DocumentsDirectoryの代わりになるものは何ですか? system.ResourceDirectory を使用できないため、唯一の読み取り可能であり、書き込み可能ではありません
これは、ユーザーがインストール後にゲームをプレイする前に最初にハイスコアをチェックする場合に使用される私のhighscore.lua用です
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