# \[Solved\] Help using any component blocks to set variables

**URL:** <https://community.thunkable.com/t/solved-help-using-any-component-blocks-to-set-variables/422048>\
**Category:** Questions about Thunkable X\
**Tags:** solved, variables\
**Created:** [January 22, 2020, 7:42pm UTC](https://community.thunkable.com/t/solved-help-using-any-component-blocks-to-set-variables/422048 "2020-01-22T19:42:01Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)\
**Post date:** [January 22, 2020, 7:42pm UTC](https://community.thunkable.com/t/solved-help-using-any-component-blocks-to-set-variables/422048/1 "2020-01-22T19:42:01Z")

</div>

I have 5 dynamic rows with 5 buttons in each.  
each row is assigned 1 variable

so, the user picks 1 option (clicks 1/5 buttons) and i want that button choice assigned to the button for that row. currently my code for that looks like this.

 ![Screen Shot 2020-01-22 at 2.03.58 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/2/92b9fd73f144958a140664bb34172ac512332fad.png)  
i have shortened it to this  
 ![Screen Shot 2020-01-22 at 2.29.48 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/9/49c97d716b7577cf1f062221a170c0b583226cbf.png)

if you can see each row 60-64 is assigned to it’s own Dataformat variable. Is there a way to combine these into less blocks? or since i am dealing with variables, does each need it’s own set of control blocks?

in row 60 there would be 5 buttons. when any of the buttons is clicked i want storedbehaivor1 set to that buttons text.

i want to do that for rows 60/storedbehavior1, row 61/storedbehavior2 etc.

---

<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:** [January 22, 2020, 8:23pm UTC](https://community.thunkable.com/t/solved-help-using-any-component-blocks-to-set-variables/422048/2 "2020-01-22T20:23:41Z")

</div>

In the second screenshot, it looks like what you’re doing is taking the button ID (_component_), checking to see if it’s a button in a particular column and row, and if so, changing its property.

Is there a reason you’re checking to see if each button is part of a column and part of a row?

This looks like an inefficient way to check a button’s membership. Why not just create a list of button #s and then check that list _once_ when a button is clicked to see if it’s a member? That way instead of having a bunch of loops (for j from 1 to 5), you just have a single list lookup.

---

<div class="post-metadata">

**Author:** ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)\
**Post date:** [January 22, 2020, 8:28pm UTC](https://community.thunkable.com/t/solved-help-using-any-component-blocks-to-set-variables/422048/3 "2020-01-22T20:28:09Z")

</div>

sure! great point! column 10 is made up of several rows for formatting purposes. maybe i could use some guidance here. idk how else to make it looks the right way

 ![Screen Shot 2020-01-22 at 3.15.39 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/1/b1e93f7cabdf0b47d573085c329c7d8df174045d.png)

---

<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:** [January 22, 2020, 8:28pm UTC](https://community.thunkable.com/t/solved-help-using-any-component-blocks-to-set-variables/422048/4 "2020-01-22T20:28:21Z")

</div>

The variable aspect is a little tricky. I’m not sure how the local database works – is that what you’re using with all those BX4\_Dataformat variables? – but if you can specify a row/column pair or use a list and store the whole list, you can use index values to save things in a single block (as I suggested just above) instead of having separate variable values everywhere.

As a general rule of thumb, if you’re creating multiple variables that have to be numbered (Level 1 score, Level 2, score, Level 3, score, etc.), that’s a good indication that a list or table is a way better way of storing that information.

---

<div class="post-metadata">

**Author:** ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)\
**Post date:** [January 22, 2020, 8:31pm UTC](https://community.thunkable.com/t/solved-help-using-any-component-blocks-to-set-variables/422048/5 "2020-01-22T20:31:09Z")

</div>

oh boy! a new challenge! figuring out how to do that would save me so many variables. it would just require remembering the correct index fora beahvior.

your example would be something like

Var Stored behaviors: index 1, behavior 1; index 2, beavhior 2 etc?

---

<div class="post-metadata">

**Author:** ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)\
**Post date:** [January 22, 2020, 8:34pm UTC](https://community.thunkable.com/t/solved-help-using-any-component-blocks-to-set-variables/422048/6 "2020-01-22T20:34:07Z")

</div>

![Screen Shot 2020-01-22 at 3.22.56 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/9/992a95a8a058c6c40e9a84c3a4f00e4cc22acbd2.png)

take out the loop?

---

<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:** [January 22, 2020, 8:41pm UTC](https://community.thunkable.com/t/solved-help-using-any-component-blocks-to-set-variables/422048/7 "2020-01-22T20:41:53Z")

</div>

Possibly! Do you know why you’re checking to see if a button is part of a row or column? If there’s not a specific reason, I think you can replace the multiple loops with something better.

---

<div class="post-metadata">

**Author:** ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)\
**Post date:** [January 23, 2020, 6:47pm UTC](https://community.thunkable.com/t/solved-help-using-any-component-blocks-to-set-variables/422048/8 "2020-01-23T18:47:59Z")

</div>

I had to play with this but it makes sense. I was able to reduce in a test app 16 to a single list saved in 1 variable. i will share the code and app here. it is a simple discrete trial teaching data collection tool used in an ABA therapy setting.

currently the app is set up to measure 5 things in a % format. it only takes 18 blocks total and 0 extra variables per measure now instead of wayy more.

I have also made use of the anycomponent blocks a lttle bit more!

 ![Screen Shot 2020-01-23 at 1.31.17 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/c/bcc742e84c8f37dcd2edd8d1c065ceeaae55061e.png)

[https://x.thunkable.com/copy/5c7372490965e9191353fe5055816f74](https://x.thunkable.com/copy/5c7372490965e9191353fe5055816f74)

---

<div class="post-metadata">

**Author:** ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)\
**Post date:** [November 8, 2024, 11:45am UTC](https://community.thunkable.com/t/solved-help-using-any-component-blocks-to-set-variables/422048/9 "2024-11-08T11:45:53Z")

</div>


