Propoer Implementation of datastore

I'm using VS Code to build a project for Playdate.

I'm having issues using datastore properly. I'm able to write to "sav" using datastore.write, but what I need to do next is draw data from that .json file. Inside Playdate says that returns a table. However, I haven't had any luck seeing the data after trying to use

I've tried what I thought would work, such as:

local someTable ="sav")

Yet when I test the table to see what is in it (using printTable(someTable)), I get an empty table.

Anyone know what I'm doing wrong?

You need to specify the filename you saved it to. Default is "data". The name of your original table isn't included in the save data.

-- set table
sav = {x=10, y=20, label="something"}
-- write save data
playdate.datastore.write(sav, "file")
-- clear table
sav = {}
-- load save data
sav ="file")
-- print loaded data

Thanks for the reply.

What I had was essentially what you posted: my issue was that I wasn't calling the function that displayed sav.json contents appropriately.

Thanks again!

1 Like