Save/restore settings generated by the settings page

What I would like to achieve is:

  • if my app is launched without options, the generic settings screen is shown before starting (as in a default SimpleApplication)
  • if my app is launched with some options (–nosettings), is it started directly, with the last used/saved settings

I know settings chosen on the settings screen are saved somewhere, because options are remembered between runs, but I could not retrieve them, or have the settings screen interact with my own instance of AppSettings.

Is this possible ?

This seems easy to me so maybe I’ve misunderstoof. If you see the --nosettings in the arguments to main() then set show settings to false:

if (args.contains("--nosettings") setShowSettings(false);

b) On my Devices the Settings aren’t saved automatically, but:
You can use and appSettings.load() to load them from a file, the Engine will then auto-care about serialization

(Though I would prefer a manual-xml-file, because then the Users can change the resolution in the config aswell)

Sorry maybe I should have given more details:
setShowSetting(false) seems to use some “default” settings freshly created, but definitely not the ones chosen the last time the settings screen was used.

So this doesn’t work:

if (args.contain("--nosettings") {

I would need something like:

if (args.contain("--nosettings") {
  AppSettings s = retrieveThemSomehow()
// possibly save settings here, but there's no getSettings() to access what settings were created

So I would need either getSettings() or retrieveThemSomehow(). I noticed that in ~/.java/.userPrefs I have a very strange folder (named literally: _!'o!^@“v!'4!aw"l!(k!)!”&!'4!~w"p!'4!~@!g!$:!.g!w) that contains the saved preferences, but I’d rather not hardcode the loading of something named so.

AppSettings settings = new AppSettings();

This will create/use some default settings. I don’t want 2 completely independent operation modes, I want interaction between them: the settings a user chooses when the setting dialog pops are the ones that have to be used later, when launching with --nosettings.

Did you even try it?

It should use the last settings the user specified.

It’s almost like I’ve done this before somehow and know what I’m talking about.

Actually, it seems broken now. This used to work but I guess someone busted it sometime.

For whatever reason, if you don’t show the settings dialog then there is a bunch of stuff missing from AppSettings and your app will crash.

Ok, so… AppSettings is a pretty ridiculous class and counterintuitive in like 50 different ways.

If you create a new AppSettings(false) then it will automatically load your last values… but it leaves a bunch of things unset. If you try to run your app this way without showing the settings dialog then it will be missing a bunch of stuff and probably crash.

However, if you create a new AppSettings(true) then it will load defaults for everything but otherwise ignore any settings that you had saved before.

So, the trick is some counterintuitive funky combination of loading defaults as well as loading the settings.

First, this presumes that you’ve given yourself an app title because I think that’s what’s used for saving the settings.

AppSettings settings = new AppSettings(true); // ← so things will get set and the app won’t crash

…then setShowSettings() as you wish. If the user selected settings previously they will be loaded with the load(titleOfYourApp) above.

Yes I tried it and it crashed indeed :smile:
That is, with new AppSettings(false) . With true instead, it’s back to defaults (as it should be, from the name).

Ok I tested your “funky combination” and it works as I want, thanks !
The secret (for me) link was the title used as save name (and funky default title !).

For what it’s worth, and if you can change things easily, I would have found handy to have a method to create settings via a dialog, but outside of an app run. For example in AppSettings:

static AppSettings CreateFromDialog();

Anyway, thanks again !