I know, I suck at coding, I just really need help (for the 7-billionth time). I can't figure out how to use playdate.datastore.read([filename]). I have this:
import "CoreLibs/graphics"
import "CoreLibs/object"
import "CoreLibs/sprites"
import "CoreLibs/nineslice"
import "CoreLibs/timer"
import "CoreLibs/graphics"
import "CoreLibs/ui"
import "CoreLibs/animation"
import "CoreLibs/animator"
import "CoreLibs/crank"
import "config"
import "core/definitions"
import "core/cotton/all"
import "scripts/index"
import "core/lieb/all"
import "core/CoreGame"
save = {
money = 100,
billValue = 20,
managers = 4,
printers = 5,
lastTime = playdate.getTime()
}
save = playdate.datastore.read(data)
playdate.ui.crankIndicator:start()
local gfx <const> = playdate.graphics
local printerSprite = nil
local function initialize()
printerImage = gfx.image.new("images/Printer")
printerSprite = gfx.sprite.new(playerImage)
printerSprite:moveTo(200, 120)
printerSprite:add()
end
initialize()
LDtk.load("levels/world.ldtk", shouldUseFastLoader())
if playdate.isSimulator then
LDtk.export_to_lua_files()
end
local printerPicture = playdate.graphics.image.new("images/printer")
local cashPicture = playdate.graphics.image.new("images/cash")
local animatorY = playdate.graphics.animator.new(2000, 120, 240)
local myInputHandlers = {
cranked = function(acceleratedChange)
-- use the printer
if acceleratedChange > 50 then
if printers ~= 0 then
money = money + (billValue * printers)
end
end
end,
}
local menu = playdate.getSystemMenu()
playdate.gameWillPause = function()
menu:removeAllMenuItems()
if money >= 100 then
local addPrinter = menu:addMenuItem("+Printer", function()
money = money - 100
printers = printers + 1
end)
end
if money >= 150 then
if managers <= printers then
local addManager = menu:addMenuItem("+Manager", function()
money = money - 150
managers = managers + 1
end)
end
end
if billValue == 20 then
if money >= 1000 then
local billValueIncrease20 = menu:addMenuItem("+Bill Value", function()
money = money - 1000
billValue = 50
end)
end
end
if billValue == 50 then
if money >= 2000 then
local billValueIncrease50 = menu:addMenuItem("+Bill Value", function()
money = money - 2000
billValue = 100
end)
end
end
end
scene.set(game, LDtk.playerStartLocation)
function playdate.update()
input.update()
gfx.sprite.update()
scene.update()
if config.showFPS then
playdate.drawFPS()
end
if playdate.isCrankDocked() == true then
if printers >= 1 then
playdate.ui.crankIndicator:update()
end
end
playdate.timer.updateTimers()
playdate.inputHandlers.push(myInputHandlers)
playdate.graphics.drawText("*Money:* " .. money, 40, 200)
playdate.graphics.drawText("*Printers:* " .. printers, 20, 25)
printerPicture:draw(100, 60)
if playdate.getCrankChange == 50 then
cashPicture:draw(170, animatorY:currentValue())
end
cashPicture:draw(170, animatorY:currentValue())
end
function playdate.gameWillTerminate()
playdate.datastore.write(save, data)
end
function managerManaging()
if managers > 0 then
money = money + (billValue * managers)
end
end
playdate.timer.keyRepeatTimerWithDelay(5000, 5000, managerManaging)
I'm trying to save how much money, managers, printers, and the bill value each time you close the game so that it's the same when you open it back up, but I checked the JSON file that it created, and it was exactly the same as what I declared the variables at at the top. I also need the time so that I can subtract the time when the game was last closed with the time when it's opened to determine how much money you've made. Can you help with this stuff? I want to finish this game today, because I don't have a lot of free time tomorrow, and the deadline is 7:00 tomorrow. Also, I need to play an animation when you use the crank, but if you use the crank really fast, it needs to duplicate and not just reset. Can you guys please help with this?