Setup
The first step is getting the lume library
https://raw.githubusercontent.com/rxi/l ... r/lume.lua
Make a file called lume.lua in your project and paste that code in
Next require it in love.load
Code: Select all
lume = require "lume"
Main functions and code
Then we move on to our key functions
Saving
Code: Select all
function saveGame()
--making a table to save
data = {}
--saving the table(player) as another table inside of data(data.player)
data.player = player
--saving the table(reasources) as another table inside of data(data.reasources)
data.reasources = reasources
--this saves the data table to savedata.txt
serialized = lume.serialize(data)
love.filesystem.write("savedata.txt", serialized)
end
Code: Select all
function dataLoad()
--read the data
file = love.filesystem.read("savedata.txt")
data = lume.deserialize(file)
--a variable I made in my player table to check if they are a new player with no save(optional)
if data.player.newP == false then
--setting the game tables to the save tables
player = data.player
reasources = data.reasources
end
end
Some extra explanation on "data.player.newP" (OPTIONAL)
The way I called save and load was by calling the load function at the start and save every time the player moved, something to know about calling load immediately is that if theres no data on the file(savedata.txt) then you will error out so my solution was to add a variable to my player table called newP which when the game starts is true, when the load function runs if in the file newP is = to false then that means that player has played before and if it comes back negative then it wont load data allowing the player to start with the base table. One last this explaining this is that when the player moves for the first time they set newP to false and that saves on their file which is why this new player system works
Hope this helped someone! Also this info is just a combination of discord help, trial and error, and https://sheepolution.com/learn/book/21