Yes, it is!
Code: Select all
local LevelName = Level.filename()
local CoinData = SaveData._basegame.starcoin[LevelName]
local COLLECTED = 2
local SAVED = 1
function onExit()
for i = 1,CoinData.maxID do
if CoinData[i] and CoinData[i] >= COLLECTED then
CoinData[i] = SAVED
SaveData._basegame.starcoinCounter = SaveData._basegame.starcoinCounter + 1
end
end
end
This little snippet of code will save your Star Coins whenever you exit a level, even if you lose a life while doing so! The only real caveat is that it doesn't do anything if you exit the game from the pause menu mid-level because the game doesn't save, though I'd expect that that's not really what you're worried about. Funnily enough, literally all it is is just some of the code from the Star Coin AI file, just without the "actually winning the level" condition.
On a side note, once you're done with your level, could you send me a DM of it or the episode it's a part of? I'd love to check it out!