Some useful information regarding GGData module

Hi all,

This is really not a question, more of observation.

I just spent 3-4 hours troubleshooting sound in my new game.

I am using GGData module.

So I did this:

local defaults = {} defaults.soundON = true

Everytime I changed soundON like this:

settings.set("soundON", false)

Rightafter you exit app, and re-start it from very beggining, soundON will be true!  :smiley:

Main lesson: if you are using GGData start with all default parameters as “false”, and you will be fine   :smiley:

Do not start with true. 

It is a great module by the way!

Ivan

This isn’t correct.  Are you first checking to see if the setting exists?  On every app start you should first check to see if the setting is nil, and if so save it to whatever you want the default to be.  After this load the setting value from file.  Here’s an example:

main.lua:

local savedSettings = GGData:new("settings") if savedSettings.sfx == nil then savedSettings.sfx = "on" end if savedSettings.music == nil then savedSettings.music = "on" end savedSettings:save() local sounds = require('libs.sounds') --my own personal sound library sounds.isSoundOn = savedSettings.sfx == "on" sounds.isMusicOn = savedSettings.music == "on"

Also, don’t forget to save your settings every time you set it:

settings.set("soundON", false) settings:save()

Note: I’ve gotten into the habit of storing strings like “on” “off” instead of booleans.  If I remember correctly it’s because there’s an issue saving booleans to iCloud.

Thanks JonPM, amazing!

“on” and “off” are much more reliable than “true” and “false”.

Everything works now perfectly!

This isn’t correct.  Are you first checking to see if the setting exists?  On every app start you should first check to see if the setting is nil, and if so save it to whatever you want the default to be.  After this load the setting value from file.  Here’s an example:

main.lua:

local savedSettings = GGData:new("settings") if savedSettings.sfx == nil then savedSettings.sfx = "on" end if savedSettings.music == nil then savedSettings.music = "on" end savedSettings:save() local sounds = require('libs.sounds') --my own personal sound library sounds.isSoundOn = savedSettings.sfx == "on" sounds.isMusicOn = savedSettings.music == "on"

Also, don’t forget to save your settings every time you set it:

settings.set("soundON", false) settings:save()

Note: I’ve gotten into the habit of storing strings like “on” “off” instead of booleans.  If I remember correctly it’s because there’s an issue saving booleans to iCloud.

Thanks JonPM, amazing!

“on” and “off” are much more reliable than “true” and “false”.

Everything works now perfectly!