How do you make settings?

In an app I have I have a screen for settings. But I cant figure out how to get the switch controlling the background color to stay on. If I turn it on leave and come back it just turns off.

1 Like

There are two events where you can retrieve the setting (true/false) from TinyDB:

  • Screen.Initialize
  • When Other Screen Closed.

Of course, you have to remember to store the setting in TinyDB after you change it.

The other screens change color but when I go back to the setting if it was set to white it will automatically go back to dark

(Canned Reply: ABG- Export & Upload .aia)
Export your .aia file and upload it here.

export_and_upload_aia

.

Chromebox_V3_3.aia (728.2 KB)


TinyDB tags are case sensitive.

So decide between 'switch mode' and 'Switch mode', and stick to that.

Also, don't forget to add an Else clause to where you decide what to set the switch state to, to cover both the On and Off cases.

P.S. What's with the free floating blocks?

I am still like spit balling ideas and adding/ taking away so it gets messy and thx

Is this better?

Same deal, but with 'light mode' vs 'Light mode' for a certain global variable value.

You can avoid all that by hard coding constant global values once, in all caps, and then referring only to the global variable names from then on, and never typing in new text blocks.

That's three global variables to init:

  • LIGHT_MODE_TAG
  • LIGHT_MODE_ON_VALUE
  • LIGHT_MODE_OFF_VALUE

Here is a simple "settings" example:

Screen1

image

SignIn

image

Settings

AIA:
settings.aia (5.5 KB)

I need simpler things, so I took a shot at making it simpler:

Screen1:

Settings:

signin:

Sample run:

Sample run

( I see now that I missed a few places where I should have called my isDark value procedure instead of doing a TinyDB lookup. The idea of the procedure was to encapsulate that decision.)

settings (1).aia (7.3 KB)

P.S. I used the Backpack to copy the global init and the procedure definitions, to avoid error.

(I ran into an AI2 bug when I tried to drag in code referencing Any Vertical Arrangement into a Screen that had no Vertical Arrangements. It triggered an Ai2 Bug Report.
(a Drag and Plotz))