[Solved] Save attribute values


What’s the appropriate way to save some object attribute so that they remain the same if I close the app and then re-open it?

Specifically, I have checkboxes (buttons for which I change the background color when they are cliked, red=unchecked, green=checked). I would like the checkboxes to retain their state whenever I leave the app and comeback.

Here is a screen shot and my code so far:

1 Like

Instead of using initialize “app” variables, try to just change each one to stored. Don’t forget to change the variables that are called to stored as well. Hopefully it works, if not, hopefully a more experienced thunker can jump in and tell me where I went wrong. :grin:

Edit to add: from what I understand “app” variables only persist while the app is open. “Stored” variables persist in the user’s device even while closed.

1 Like

Thanks for answering!

So it’s not really the app variables for defining checked_color and unchecked_color that I want to get rid of. It’s that I want to save the attributes of my buttons but in a concise and efficient manner.

The following code is doing what I want, but the issue is that it doesn’t scale. If I had 20 buttons instead of 3 it would be a real mess:

1 Like

There is more than one way to do this. You can use a Local Data Source and store all button state in it. Every time the app starts it should read all values and update the app.

Another way is using the stored variable but make it a list. In the list put all the states for each button but you will have to remember them as sequence of numbers.

A better way is to use a stored object. In the object you but the button name and the color state.

In all methods you will need to go through a loop to read the values and update the buttons.

Hope that helps.

1 Like

I see! I think I figured it out with Stored Variables. Thanks for the help!

Glad you were able to figure it out. Wish I had been able to help more. Happy thunking!