(Note this problem is not about SSK2, it is just a warning that there will be SSK2 calls)
Hello, everyone. I am currently working on having my character collect coins and save the data to the phone. However, I have come across an issue, it seems as if an incorrect number of coins is being saved to the phone. I tested this by adding a print statement and found that the number of coins printed in the console and saved to the text file is different. The picture is posted below.
Here is the code:
function coin:collision(event) if event.phase == "began" then if event.other.name == "character" then display.remove(self) print("coin collected") coinCount = coinCount + 1 coinText.text = coinCount if io.exists("coin.txt") then local coinCountInt = tonumber(io.readFile("coin.txt")) + 1 local coinCountString = tostring(coinCountInt) io.writeFile(coinCountString, "coin.txt") print(coinCountString) else local coinCountString = tostring(coinCount) io.writeFile(coinCountString, "coin.txt") print(coinCountString) end end end end coin:addEventListener("collision")
It might be something with how I am counting my coins, but the variable being saved to the file is the same one being printed in the console, so I don’t know why the difference occurs.