Hey Lovers,
I am working on my platformer game and i`d like to know a way for saving/loading my levels.I know i should do something with love.filsystem, and i`ve tried a couple of things but i can`t write and save a level correctly.
So let me explain you better,i have a variable that stores my current level and its name is "gameLevel" ,every time when i pass a level this variable increments +1 and it loads a new map.But now if the user exists the game i want to store the current "gameLevel" somewhere in my PC and when the user restarts the game it will resume.
If you can give me an exemple i`d be very happy.
Have a nice day
[Help]Saving/Loading
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[Help]Saving/Loading
I found Love very enjoyable and nice!
Re: [Help]Saving/Loading
Coincidentally i was trying to figure this out for myself just yesterday. I'll attach what i came up with, It's capable of saving and loading a string, It might help you get started.
the way the demo works is you press "s" and it will add a random number to the file, Then on next run it should load that same file and display it.
Keep in mind this is probably not ideal as it's my very first experience with files in löve.
Also worth mentioning is it saves the file in this directory: "C:\Users\your_username\AppData\Roaming\LOVE\whatever_the_game_is_called"
the way the demo works is you press "s" and it will add a random number to the file, Then on next run it should load that same file and display it.
Keep in mind this is probably not ideal as it's my very first experience with files in löve.
Also worth mentioning is it saves the file in this directory: "C:\Users\your_username\AppData\Roaming\LOVE\whatever_the_game_is_called"
Re: [Help]Saving/Loading
If you are willing to use a third party library I would suggest you try "TSerial" to serialize a table and
then reload it on start. It's pretty easy to use :
Save:
Load:
tip : with love.filesystem.read / write you don't need to open() / set file:write() or file:read() / close() the file, that will be done automatically.
EDIT: Here's a demo love on what I mean! ( number saves on quit ).
then reload it on start. It's pretty easy to use :
Save:
Code: Select all
love.filesystem.write( "level.lua", TSerial.pack(levelinfo) )
Code: Select all
love.filesystem.setIdentity( "YourGameName" ) -- Saving directory
if love.filesystem.exists( "level.lua" ) then
levelinfo = TSerial.unpack( love.filesystem.read("level.lua") )
end
EDIT: Here's a demo love on what I mean! ( number saves on quit ).
Re: [Help]Saving/Loading
I wrote an easy-to-use saving script a while ago https://github.com/Lafolie/Jupiter.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot], Semrush [Bot] and 6 guests