[SOLVED] Different approaches for saving settings and game progress

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.
Post Reply
User avatar
Link
Prole
Posts: 14
Joined: Tue Jun 19, 2018 4:09 am

[SOLVED] Different approaches for saving settings and game progress

Post by Link » Wed Jul 18, 2018 10:56 am

I need to save game settings (e.g. video & audio settings) and game progress (e.g. which levels are completed, high-scores for each level).

What method are others using? Some ideas I had:
  • Using a Lua table structure to represent the settings, and serializing to a file (there seem to be many serialization libraries)
  • Saving to a JSON or XML file
  • Using an embedded database such as SQLite through a Lua wrapper library (would add complexity to the game distribution)
Thanks
Last edited by Link on Thu Jul 19, 2018 7:29 pm, edited 1 time in total.

Nelvin
Prole
Posts: 36
Joined: Mon Sep 12, 2016 7:52 am

Re: Different approaches for saving settings and game progress

Post by Nelvin » Wed Jul 18, 2018 1:22 pm

Use Lua ... there's hardly any sane reason not to do so for this kind of data.

User avatar
Nixola
Inner party member
Posts: 1932
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Different approaches for saving settings and game progress

Post by Nixola » Wed Jul 18, 2018 10:19 pm

One reason would be safety. Lua code would need to be sandboxed, or people sharing modified saves could potentially run untrusted code through them.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics

User avatar
ivan
Party member
Posts: 1309
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Different approaches for saving settings and game progress

Post by ivan » Thu Jul 19, 2018 1:29 am

Yes, using Lua is by far the most sensible choice.
I like to load the default options (read-only) file as a table from the game directory,
then I look for a "custom" or saved options file in the appdata directory.
Then I merge the fields from the two tables if the types match:

Code: Select all

for k, v in pairs(default) do
  if type(v) == type(custom[k]) then
    default[k] = custom[k]
  end
end
This ensures that no junk gets loaded from the options file,
but you still need a little bit of sandboxing if you are going to use the appdata directory.
Always a good idea to separate the game settings from the progress save file.

Nelvin
Prole
Posts: 36
Joined: Mon Sep 12, 2016 7:52 am

Re: Different approaches for saving settings and game progress

Post by Nelvin » Thu Jul 19, 2018 6:39 am

Nixola wrote:
Wed Jul 18, 2018 10:19 pm
One reason would be safety. Lua code would need to be sandboxed, or people sharing modified saves could potentially run untrusted code through them.
Right, that's one of the few cases.

Controlling the environment (using setfenv) while loading a game might help in situations where additional safety is required.

User avatar
ivan
Party member
Posts: 1309
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Different approaches for saving settings and game progress

Post by ivan » Thu Jul 19, 2018 5:15 pm

Actually, I would go one step further and say that regardless of the format, safety should always be of concern.
It doesn't really matter if you use Lua, XML, JSon, SQL - all of these formats could probably be exploited in one way or another.
It's really a question of what's practical in your case.
Last edited by ivan on Fri Jul 20, 2018 5:02 am, edited 1 time in total.

User avatar
Link
Prole
Posts: 14
Joined: Tue Jun 19, 2018 4:09 am

Re: Different approaches for saving settings and game progress

Post by Link » Thu Jul 19, 2018 7:29 pm

Thanks everyone, I'm going to stick with a Lua table using the techniques suggested. :cool:

User avatar
D0NM
Party member
Posts: 189
Joined: Mon Feb 08, 2016 10:35 am
Location: Zabuyaki
Contact:

Re: [SOLVED] Different approaches for saving settings and game progress

Post by D0NM » Fri Jul 20, 2018 5:58 am

You may use our module to save config into .lua file and load it later.
It has some defaults, etc.

https://github.com/thomasgoldstein/zabu ... ration.lua

Just add a reference to our site and the authors ))
Our LÖVE Gamedev blog Zabuyaki (an open source retro beat 'em up game). Follow @Zabuyaki.
Twitter @FaMeSoft / GP32 Free Platformer: SUPER PLUSHA
:joker: LÖVE & Lua Video Lessons in Russian / Видео уроки по LÖVE и Lua :joker:

User avatar
Link
Prole
Posts: 14
Joined: Tue Jun 19, 2018 4:09 am

Re: [SOLVED] Different approaches for saving settings and game progress

Post by Link » Fri Jul 20, 2018 10:21 am

D0NM wrote:
Fri Jul 20, 2018 5:58 am
You may use our module to save config into .lua file and load it later.
It has some defaults, etc.

https://github.com/thomasgoldstein/zabu ... ration.lua

Just add a reference to our site and the authors ))
Thanks, but your code seems to use the license "Attribution-NonCommercial 4.0 International" and I'm hoping to potentially sell my game (if it's ever finished). I'm sticking to libraries under the MIT License.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 10 guests