Anotther difficulty

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
BoonyBuny
Prole
Posts: 31
Joined: Mon Jun 13, 2022 1:24 am
Location: France
Contact:

Anotther difficulty

Post by BoonyBuny »

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? :cry:
A coding begginer that is migrating from 8 years of Scratch... yea yikes. :emo:
User avatar
BrotSagtMist
Party member
Posts: 607
Joined: Fri Aug 06, 2021 10:30 pm

Re: Anotther difficulty

Post by BrotSagtMist »

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.
obey
User avatar
BoonyBuny
Prole
Posts: 31
Joined: Mon Jun 13, 2022 1:24 am
Location: France
Contact:

Re: Anotther difficulty

Post by BoonyBuny »

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
A coding begginer that is migrating from 8 years of Scratch... yea yikes. :emo:
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: Anotther difficulty

Post by ReFreezed »

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."
User avatar
BoonyBuny
Prole
Posts: 31
Joined: Mon Jun 13, 2022 1:24 am
Location: France
Contact:

Re: Anotther difficulty

Post by BoonyBuny »

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. :emo:
User avatar
togFox
Party member
Posts: 770
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: Anotther difficulty

Post by togFox »

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
User avatar
darkfrei
Party member
Posts: 1169
Joined: Sat Feb 08, 2020 11:09 pm

Re: Anotther difficulty

Post by darkfrei »

Can we have some "serialize-and-save" library inbuild in the Löve?
It must be as easy as

Code: Select all

ScoreData={bestscore, coins}
love.filesystem.serializeAndWrite("data.txt", ScoreData)
or

Code: Select all

ScoreData={bestscore, coins}
love.filesystem.write("data.txt", love.serialize(ScoreData))
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.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
Andlac028
Party member
Posts: 174
Joined: Fri Dec 14, 2018 2:27 pm
Location: Slovakia

Re: Anotther difficulty

Post by Andlac028 »

darkfrei wrote: Mon Jun 27, 2022 7:09 am Can we have some "serialize-and-save" library inbuild in the Löve?
Actually, there is love.data.pack and love.data.unpack, but it requires you to specify formatting string...
MrFariator
Party member
Posts: 509
Joined: Wed Oct 05, 2016 11:53 am

Re: Anotther difficulty

Post by MrFariator »

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.
User avatar
BoonyBuny
Prole
Posts: 31
Joined: Mon Jun 13, 2022 1:24 am
Location: France
Contact:

Re: Anotther difficulty

Post by BoonyBuny »

This seems awfully complicated, I'll document myself on the Ser library today and tinker things around until it works :roll:
A coding begginer that is migrating from 8 years of Scratch... yea yikes. :emo:
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 49 guests