# Colors in stored variables

**URL:** <https://community.thunkable.com/t/colors-in-stored-variables/2602843>\
**Category:** Questions about Thunkable X\
**Tags:** beginner, help\
**Created:** [September 19, 2023, 9:45am UTC](https://community.thunkable.com/t/colors-in-stored-variables/2602843 "2023-09-19T09:45:06Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![frederikdeclercq44o1](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/frederikdeclercq44o1/32/157652_2.png) [@frederikdeclercq44o1](https://community.thunkable.com/u/frederikdeclercq44o1)\
**Post date:** [September 19, 2023, 9:45am UTC](https://community.thunkable.com/t/colors-in-stored-variables/2602843/1 "2023-09-19T09:45:06Z")

</div>

![Schermafbeelding 2023-09-19 113014](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/c/a/ca98143f786316ae55ec9b75d6e6da6cf540b949.png)  
I’m an absolute beginner. I have a button and want the App to save the last clicked color of the button, so when I close and reopen the App I know what the last button was, that was clicked. Because of the difference in color between the design screen en the Blocks screen you have to set "when screen1 opens set to button’s background cloor to…So it doesn’t work with a stored variable.

---

<div class="post-metadata">

**Author:** ![domhnallohanlon](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/domhnallohanlon/32/29554_2.png) [@domhnallohanlon](https://community.thunkable.com/u/domhnallohanlon)\
**Post date:** [September 19, 2023, 1:03pm UTC](https://community.thunkable.com/t/colors-in-stored-variables/2602843/2 "2023-09-19T13:03:45Z")

</div>

Hey @frederikdeclercq44o1, welcome to the Community 👋

> [@frederikdeclercq44o1](#):
>
> So it doesn’t work with a stored variable.

At the moment though you’re not storing the colour values in your variable - is that the issue?

---

<div class="post-metadata">

**Author:** ![frederikdeclercq44o1](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/frederikdeclercq44o1/32/157652_2.png) [@frederikdeclercq44o1](https://community.thunkable.com/u/frederikdeclercq44o1)\
**Post date:** [September 19, 2023, 2:50pm UTC](https://community.thunkable.com/t/colors-in-stored-variables/2602843/3 "2023-09-19T14:50:32Z")

</div>

I tried storing it but, it doesn’t work because: "when screen1 opens set background color to…  
If you don’t use the block “when Screen1 opens” switching colors doesn’t work.  
I want the App to store the color of my button; I don’t care how. Let’s say it’s an exercise App and when I’ve completed an exercise I push a button and it turns green. The next week when I open the App I want it to show that I have finished the exercise and the button is green. Adding a reset button …turning the button to the starting color.

---

<div class="post-metadata">

**Author:** ![domhnallohanlon](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/domhnallohanlon/32/29554_2.png) [@domhnallohanlon](https://community.thunkable.com/u/domhnallohanlon)\
**Post date:** [September 19, 2023, 4:51pm UTC](https://community.thunkable.com/t/colors-in-stored-variables/2602843/4 "2023-09-19T16:51:46Z")

</div>

> [@frederikdeclercq44o1](#):
>
> If you don’t use the block “when Screen1 opens” switching colors doesn’t work.

I’m not sure what you mean here - this was my approach and the value is stored between sessions.

 ![Screenshot 2023-09-19 at 17.49.19](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/f/5f086e92a29495c03a45149c00e2648b8d68d92f.png)

1. Test for the initial, empty state and set the button to the default colour
2. Write the new value to the variable every time a change occurs

Try it out:  
[https://x.thunkable.com/copy/03bcaaddf3b516407723bd8266b16f81](https://x.thunkable.com/copy/03bcaaddf3b516407723bd8266b16f81)

---

<div class="post-metadata">

**Author:** ![vishruth-ram](https://avatars.discourse-cdn.com/v4/letter/v/82dd89/32.png) [@vishruth-ram](https://community.thunkable.com/u/vishruth-ram)\
**Post date:** [September 21, 2023, 3:24am UTC](https://community.thunkable.com/t/colors-in-stored-variables/2602843/5 "2023-09-21T03:24:23Z")

</div>

Hi everyone  
Just like @frederikdeclercq44o1 said, if I store something in a variable, it resets the next time open the app.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [September 21, 2023, 5:37am UTC](https://community.thunkable.com/t/colors-in-stored-variables/2602843/6 "2023-09-21T05:37:01Z")

</div>

Then you aren’t using _stored_ variables correctly.

Post a screenshot of your blocks.

---

<div class="post-metadata">

**Author:** ![frederikdeclercq44o1](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/frederikdeclercq44o1/32/157652_2.png) [@frederikdeclercq44o1](https://community.thunkable.com/u/frederikdeclercq44o1)\
**Post date:** [September 21, 2023, 10:01am UTC](https://community.thunkable.com/t/colors-in-stored-variables/2602843/7 "2023-09-21T10:01:51Z")

</div>

Thanks, it kind of works. Sometimes I have to click more then once to change the color? Sometimes 3x sometimes 2x …  
I’ve added a clear button and removed some colors.

 ![Schermafbeelding 2023-09-21 115717](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/e/c/ec6beeb966e5307865e0a0282ccbdff66a78c5c4.png)  
 ![Schermafbeelding 2023-09-21 115733](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/2/b238dce94535ba378c35d09e4ef9a9f206c5b9cc.png)

---

<div class="post-metadata">

**Author:** ![domhnallohanlon](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/domhnallohanlon/32/29554_2.png) [@domhnallohanlon](https://community.thunkable.com/u/domhnallohanlon)\
**Post date:** [September 21, 2023, 1:12pm UTC](https://community.thunkable.com/t/colors-in-stored-variables/2602843/8 "2023-09-21T13:12:04Z")

</div>

> [@frederikdeclercq44o1](#):
>
> Sometimes I have to click more then once to change the color? Sometimes 3x sometimes 2x …

Sure, that makes sense, you’re randomly drawing from a list of 2 items. It’s just like flipping a coin, you might get 3 heads in a row, you might get 100 in a row, but on average it will flip back and forth every couple of clicks/flips

I only used the random colours for illustration purposes @frederikdeclercq44o1, in your case are you trying to make a toggle button, is that right?

> [@Creating a Toggle in Thunkable](https://community.thunkable.com/t/creating-a-toggle-in-thunkable/53574):
>
> You can create an on/off switch, also known as a toggle switch, in your app with a variety of different components and blocks in Thunkable X. Switch The [switch](https://docs.thunkable.com/thunkable-cross-platform/create/components/user-interface/switch) component is probably the easiest to get started with. When the switch is clicked, the value changes. The newValue variable is either true or false, depending on whether the switch is on or off. In this example, a [label](https://docs.thunkable.com/thunkable-cross-platform/create/components/user-interface/label) is used to display the words “On” or “Off” depending on the position of the string. [05] [Click to remix the “Toggl”…](https://x.thunkable.com/copy/22cb09b96dffc0d557d5feab3e481ffe)

---

<div class="post-metadata">

**Author:** ![frederikdeclercq44o1](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/frederikdeclercq44o1/32/157652_2.png) [@frederikdeclercq44o1](https://community.thunkable.com/u/frederikdeclercq44o1)\
**Post date:** [September 21, 2023, 3:55pm UTC](https://community.thunkable.com/t/colors-in-stored-variables/2602843/9 "2023-09-21T15:55:44Z")

</div>

I want to click a button, so it changes from red to green and back. (toggle) and I want to store the change, so I know what last color was which was clicked even if I close the App.(stored variable) If that is not possible, maybe a switch is an option and saving its position in a stored variable.  
Btw, Thx for all the help.

---

<div class="post-metadata">

**Author:** ![domhnallohanlon](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/domhnallohanlon/32/29554_2.png) [@domhnallohanlon](https://community.thunkable.com/u/domhnallohanlon)\
**Post date:** [September 21, 2023, 4:42pm UTC](https://community.thunkable.com/t/colors-in-stored-variables/2602843/10 "2023-09-21T16:42:31Z")

</div>

That’s what I thought - there’s no need for the `random list item` so, you just need to store the button colour.

I linked to an tutorial on creating toggles in my previous post ☝

> [@frederikdeclercq44o1](#):
>
> Maybe a switch is an option and saving its position in a stored variable.

Yep, a switch or a checkbox would also work with the same sort of logic too

---

<div class="post-metadata">

**Author:** ![frederikdeclercq44o1](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/frederikdeclercq44o1/32/157652_2.png) [@frederikdeclercq44o1](https://community.thunkable.com/u/frederikdeclercq44o1)\
**Post date:** [September 23, 2023, 10:55am UTC](https://community.thunkable.com/t/colors-in-stored-variables/2602843/11 "2023-09-23T10:55:42Z")

</div>

So it’s not possible to store the button color in a stored variable, because of the difference in color between the ‘Design’ and the ‘Blocks’ screen. I have to use a switch or a checkbox? How do I store the setting of a switch in a stored variable?  
All I wanted was when I clicked a button, the color changed and the color was stored so when I closed the App en reopened it, it showed the last shown color.  
e.g. : when clicked, button is red or green. Close App en reopen App, show last color.

---

<div class="post-metadata">

**Author:** ![domhnallohanlon](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/domhnallohanlon/32/29554_2.png) [@domhnallohanlon](https://community.thunkable.com/u/domhnallohanlon)\
**Post date:** [September 23, 2023, 12:42pm UTC](https://community.thunkable.com/t/colors-in-stored-variables/2602843/12 "2023-09-23T12:42:00Z")

</div>

It’s definitely possible, just use rgb or HEX values

---

<div class="post-metadata">

**Author:** ![frederikdeclercq44o1](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/frederikdeclercq44o1/32/157652_2.png) [@frederikdeclercq44o1](https://community.thunkable.com/u/frederikdeclercq44o1)\
**Post date:** [September 23, 2023, 5:01pm UTC](https://community.thunkable.com/t/colors-in-stored-variables/2602843/13 "2023-09-23T17:01:13Z")

</div>

It works fine on my computer, but not on my phone.

This is what I see on my laptop:

 ![Schermafbeelding 2023-09-23 184631](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/2/220d7c467393147d292af5e266d3999eadae01d2.png)  
On my phone, the screen is blank and the Blocks page looks like this:  
 ![Screenshot_2023-09-23-18-47-23-57_2bbfbfee96a5dfce998f962ebb8b5da3](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/d/0/d0178d17c50f4c984b86adee424fa7833dc12fb1.jpeg)  
 ![Screenshot_2023-09-23-18-47-37-84_2bbfbfee96a5dfce998f962ebb8b5da3](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/2/b2b3b3731b2aa8b9c53947c65f3fced21d07a352.jpeg)

The variable blocks are different???  
The toggle with the label change works, but how do I make it work with the switch? I use the drag and drop version of Thunkable.

 ![Schermafbeelding 2023-09-23 184409](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/3/0/30d2cf5235a2a15d98d57b6156884d65186be8a1.png)  
 ![Schermafbeelding 2023-09-23 184522](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/3/f31d26d3ac35b9da4a63b0bc01051b61a75dab70.png)

Only the text of the switch changes.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [September 23, 2023, 8:40pm UTC](https://community.thunkable.com/t/colors-in-stored-variables/2602843/14 "2023-09-23T20:40:39Z")

</div>

When using a stored variable, you should check to see if it’s equal to `null` when the screen opens and if it is, give it a starting value such as an empty string (“”) or a default color value.

If you want to share a link to your project, I can take a look at your blocks. I’ve saved color values in stored variables in various projects and it’s worked for me on an iPhone or web browser.

---

<div class="post-metadata">

**Author:** ![frederikdeclercq44o1](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/frederikdeclercq44o1/32/157652_2.png) [@frederikdeclercq44o1](https://community.thunkable.com/u/frederikdeclercq44o1)\
**Post date:** [September 24, 2023, 1:23pm UTC](https://community.thunkable.com/t/colors-in-stored-variables/2602843/15 "2023-09-24T13:23:05Z")

</div>

[https://x.thunkable.com/projects/65101d53a580be5304b6aa99/e3fe278a-a329-44b4-95a7-8f18cc47cb67/designer](https://x.thunkable.com/projects/65101d53a580be5304b6aa99/e3fe278a-a329-44b4-95a7-8f18cc47cb67/designer)

 ![Schermafbeelding 2023-09-24 140031](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/3/037401324c158d31627de623b9819f6f1cf7a7ec.png)  
I understand, the stored variable is empty when first used. But I can’t work out how to set it to the starting color, value or null or Empty???  
The screen starts blank, once you’ve clicked the button once, it works because the variable has a value. Correct?  
 ![Schermafbeelding 2023-09-24 142437](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/a/f/af7def9951aad3aebe94d02c2378ceb6b0200ea5.png)

Is want to do the same thing with a switch. Saving the settings of the switch in a stored variable. Do I have to have a variable for every setting, tint color, thumb tint color, switch value??? Any good tutorials.  
I really appreciate all the help.

---

<div class="post-metadata">

**Author:** ![domhnallohanlon](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/domhnallohanlon/32/29554_2.png) [@domhnallohanlon](https://community.thunkable.com/u/domhnallohanlon)\
**Post date:** [September 24, 2023, 1:34pm UTC](https://community.thunkable.com/t/colors-in-stored-variables/2602843/16 "2023-09-24T13:34:17Z")

</div>

> [@frederikdeclercq44o1](#):
>
> But I can’t work out how to set it to the starting color, value or null or Empty???

In the example I shared with you, when the screen opens we check if the stored variable has been initialised and, if not, set the button colour to grey. You can do something similar in your project

---

<div class="post-metadata">

**Author:** ![frederikdeclercq44o1](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/frederikdeclercq44o1/32/157652_2.png) [@frederikdeclercq44o1](https://community.thunkable.com/u/frederikdeclercq44o1)\
**Post date:** [September 24, 2023, 3:23pm UTC](https://community.thunkable.com/t/colors-in-stored-variables/2602843/17 "2023-09-24T15:23:23Z")

</div>

Somehow it worked with the grey block but not a block with #7ED321.  
Anyway, once the variable has a starting value it works.  
Thx for the help.

I’m trying the same thing with a switch.  
[https://x.thunkable.com/projects/65102b5470b935bd8fc41c24/b9c88b5b-e720-4af6-97ab-b6884aeb96fc/designer](https://x.thunkable.com/projects/65102b5470b935bd8fc41c24/b9c88b5b-e720-4af6-97ab-b6884aeb96fc/designer)

 ![Schermafbeelding 2023-09-24 172033](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/1/e/1eecb6ce03cf45c219a3d76f2522c3f442e75a77.png)  
It works fine on my laptop, but on my phone the color of the thumb does not change and stays green.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [September 24, 2023, 5:10pm UTC](https://community.thunkable.com/t/colors-in-stored-variables/2602843/18 "2023-09-24T17:10:20Z")

</div>

@domhnallohanlon @frederikdeclercq44o1 This seems to be less a problem with stored variables and more a problem with the switch component.

When I disconnect all of your blocks from their event blocks and add another switch will default properties, both switches change colors when I click on them in a web preview but neither of the switches change colors on my iPhone in Thunkable Live.

Modified project: [Thunkable](https://x.thunkable.com/copy/20055ef7e03de19be8247ce0f9e85ded)

---

<div class="post-metadata">

**Author:** ![frederikdeclercq44o1](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/frederikdeclercq44o1/32/157652_2.png) [@frederikdeclercq44o1](https://community.thunkable.com/u/frederikdeclercq44o1)\
**Post date:** [September 25, 2023, 11:54am UTC](https://community.thunkable.com/t/colors-in-stored-variables/2602843/19 "2023-09-25T11:54:34Z")

</div>

So the switch component doesn’t work as it should. OK. I will use buttons instead.  
Will you keep me posted?  
Thx

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [September 25, 2023, 2:06pm UTC](https://community.thunkable.com/t/colors-in-stored-variables/2602843/20 "2023-09-25T14:06:16Z")

</div>

I don’t work for Thunkable so it would be better to ask that of someone who does.

[Next page](https://community.thunkable.com/t/colors-in-stored-variables/2602843.md?page=2)
