Pulling data from Local storage with any component

The any component works great for storing large data all at once, i.e. whether or not 100 switches are on or off. How can you use the Any component to pull all of this data at once and put it into your app? If you can’t, do you have to use a separate statement for each switch?

You can definitely do something like this @bobbyj12 with the “all switches on Screen1” block, or similar

1 Like

@domhnallohanlon do you have an example of how this would work please?

Hi @bobbyj12,

Are you familiar with working with lists in your app?
You can treat the block ‘all Switch in Screen1’ as a list.

As an example, these blocks will go through every switch in Screen1.
For each switch, if the value of the switch is true, it will write a ‘1’.
If the value of the switch is false, it will write a ‘0’.

You can use something like this to pull all of the data related to your switches and put it into your app (or a spreadsheet, or a realtime DB, etc).

1 Like

Would something like this work for you?

Here’s a link to my project @bobbyj12
https://x.thunkable.com/copy/e2efa92d7207e562d0db6ccb7415c73a

2 Likes

Thanks. I understand now. Let me give it a try.

1 Like

Hello guys, I tried the blocks above but they still do not work. The switch colors change and the label changes to “1”. However, when I back out to screen 1 and load screen 2, the switch show off and grayed out, Please look at these blocks and let me know what I’m doing wrong. Thunkable x is definitely a different animal .

Hello,

The loop uses an asynchronous purple block - this is the problem. First you need to get all the data in the loop, and you need to save the data in the purple block outside the loop.

I thought I was doing that by setting the colors when the switch is on and then saving the values from those block in the local storage block.

If you do not know the difference between asynchronous and synchronous blocks, then I recommend the information at http://droidscript.ru/main/statyi/thunkablex_base7.php

1 Like