Hello! I enctountered my second major difficulty, wich is saving and loading scores...
No matter how many tutorials I watch, the code was either outdated from 11.4 or just didn't write anything in my data.txt, and it's frustrating because i just wanna write/save 2 variables, beeing the best score & the ammount of coins collected (it's an infinite game kinda like flappy bird, score is the time survived in seconds and coins is the ammount of coins collected)
I'm at a loss, honnestly. It either doesn't work at all giving blue screens or doesn't write anything or doesn't load anything, there isn't much tutorials on this... can someone briefly explain how to do it?
Anotther difficulty
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Anotther difficulty
A coding begginer that is migrating from 8 years of Scratch... yea yikes.
- BrotSagtMist
- Party member
- Posts: 613
- Joined: Fri Aug 06, 2021 10:30 pm
Re: Anotther difficulty
You need to explain the exact issues here.
Saving a file is actually so easy in love that its pretty hard to get wrong.
Eg love.filesystem.append("save", score )
Is all that is needed to create a file "save" and write the variable score into it.
So you need to give us exactly what you are trying currently to say where your bug is.
Saving a file is actually so easy in love that its pretty hard to get wrong.
Eg love.filesystem.append("save", score )
Is all that is needed to create a file "save" and write the variable score into it.
So you need to give us exactly what you are trying currently to say where your bug is.
obey
Re: Anotther difficulty
the problem explained:
when you die, if your score is > than your best score, it should save the best score into the data.txt, same with coins collected
and when the game load it should read those numbers and set the best score and coins colleted to said data.txt values
when I use:
ScoreData={bestscore, coins}
love.filesystem.write("data.txt", ScoreData)
the data.txt stays empty, so i can't even test if the score loading system works
when you die, if your score is > than your best score, it should save the best score into the data.txt, same with coins collected
and when the game load it should read those numbers and set the best score and coins colleted to said data.txt values
when I use:
ScoreData={bestscore, coins}
love.filesystem.write("data.txt", ScoreData)
the data.txt stays empty, so i can't even test if the score loading system works
A coding begginer that is migrating from 8 years of Scratch... yea yikes.
Re: Anotther difficulty
Use love.filesystem.write and love.filesystem.read to write and read save files. To save data to a file you need to serialize the data to a string first (and deserialize the string when loading). There are numerous libraries to help with that.
Last edited by ReFreezed on Sun Jun 26, 2022 11:38 pm, edited 1 time in total.
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
"If each mistake being made is a new one, then progress is being made."
Re: Anotther difficulty
I'm gonna try to figure this out after a good night of sleep, thanks for the help
A coding begginer that is migrating from 8 years of Scratch... yea yikes.
Re: Anotther difficulty
You need to turn your table into text before saving. Refreeze provided one library that does that
Last edited by togFox on Mon Jun 27, 2022 7:31 am, edited 1 time in total.
Current project:
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
Re: Anotther difficulty
Can we have some "serialize-and-save" library inbuild in the Löve?
It must be as easy as
or
So user-friendly as possible.
Of coarse you can use any other library for it, but it must be very easy for all people without experience with libraries.
It must be as easy as
Code: Select all
ScoreData={bestscore, coins}
love.filesystem.serializeAndWrite("data.txt", ScoreData)
Code: Select all
ScoreData={bestscore, coins}
love.filesystem.write("data.txt", love.serialize(ScoreData))
Of coarse you can use any other library for it, but it must be very easy for all people without experience with libraries.
Re: Anotther difficulty
Actually, there is love.data.pack and love.data.unpack, but it requires you to specify formatting string...
-
- Party member
- Posts: 512
- Joined: Wed Oct 05, 2016 11:53 am
Re: Anotther difficulty
Serialization is also a topic where it's hard to find a one-size-fits-all solution, because you may have to serialize with speed, networking, file size, or other such factors in mind. As such, it's not necessarily LÖVE's job, even if love.data.pack/unpack should work for simple cases.
Re: Anotther difficulty
This seems awfully complicated, I'll document myself on the Ser library today and tinker things around until it works
A coding begginer that is migrating from 8 years of Scratch... yea yikes.
Who is online
Users browsing this forum: Vixii and 204 guests