How to use playdate.datastore.read([filename])?

Oh wait, I just tried to do the calculation of how much money you get offline, but it gives ANOTHER error. If I'm bothering you then I can just try and figure it out myself, but if you don't mind could you help? Here's the code I'm using:

local function initialize()

    printerImage = gfx.image.new("images/Printer")

    printerSprite = gfx.sprite.new(playerImage)

    printerSprite:moveTo(200, 120)

    printerSprite:add()

    local nowTime = playdate.getTime()

    save.money = save.money +

        (

        ((save.lastTime.hours - save.lastTime.minutes) - (nowTime.hours - nowTime.minutes)) *

            (save.billValue * save.managers))

end

initialize()

And the error:

Load failed: main.lua:46: attempt to perform arithmetic on a nil value (field 'hours')
stack traceback:
main.lua:46: in local 'initialize'
main.lua:50: in main chunk
Update error: main.lua:46: attempt to perform arithmetic on a nil value (field 'hours')
stack traceback:
main.lua:46: in local 'initialize'
main.lua:50: in main chunk

if think it's supposed to be 'save.lastTime.hour' not 'save.lastTime.hours' and the same with minutes. The values can be found here Inside Playdate

I am so dumb :joy: sorry for bothering you

1 Like

Instead of using playdate.getTime(), it might be easier to use playdate.getSecondsSinceEpoch(). It will give you the time in seconds instead of splitting it up into days, hours, minutes, etc. Then (nowTime - save.lastTime) would give you the number of seconds that has passed since closing the game.

I would do that if I saw it but instead I asked GPT-3 from OpenAI and it actuall worked. The game is up and running if you want to play it:
https://beatmakerofficial.itch.io/the-money-factory