# How to assign a unique variable to dynamically created component?

**URL:** https://community.thunkable.com/t/how-to-assign-a-unique-variable-to-dynamically-created-component/1047889
**Category:** Questions about Thunkable X
**Tags:** beginner, variables
**Created:** [January 13, 2021, 4:09pm UTC](https://community.thunkable.com/t/how-to-assign-a-unique-variable-to-dynamically-created-component/1047889 "2021-01-13T16:09:47Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![sp72979rdrlbc](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/sp72979rdrlbc/32/94224_2.png) [@sp72979rdrlbc](https://community.thunkable.com/u/sp72979rdrlbc)
#### Post date: [January 13, 2021, 4:09pm UTC](https://community.thunkable.com/t/how-to-assign-a-unique-variable-to-dynamically-created-component/1047889/1 "2021-01-13T16:09:47Z")

</div>

I’m making buttons dynamically on one page, I’m essentially trying to make a new app variable each time a button is created by combining 2 initialized app variables

**Idea** :  
intialized app variable **name = var = " ";**  
intialized app variable **name = i = 0;**  
button created - assigned to var1  
button created - assigned to var2  
button created - assigned to var3

so on and so on, but I’m begging to think this isn’t possible to do in thunkable. If it is;t possible to do this then how can I make and assign a button to a variable when it’s dynamically created with thunkable?

Picture of code snippet:

 ![Thunkable - Google Chrome 1_13_2021 8_11_09 AM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/3/03c9e83f54bcbf8f6eb0c02b065bdcf9c99282d5.png)

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [January 13, 2021, 4:20pm UTC](https://community.thunkable.com/t/how-to-assign-a-unique-variable-to-dynamically-created-component/1047889/2 "2021-01-13T16:20:56Z")

</div>

Use this variable blocks

![Screenshot_20210113_063322](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/6/562672e6bd295799205c71c8ac38b63ddb171798.jpeg)

Instead of the “name” put your dynamic values in text join to make them as a new variable.

---

<div class="post-metadata">

### Author: ![drted](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/drted/32/92694_2.png) [@drted](https://community.thunkable.com/u/drted)
#### Post date: [January 13, 2021, 4:50pm UTC](https://community.thunkable.com/t/how-to-assign-a-unique-variable-to-dynamically-created-component/1047889/3 "2021-01-13T16:50:35Z")

</div>

Thanks for providing both a detailed description of what you are trying to do as well as the blocks you are using. Both are incredibly valuable to the community to make suggestions.

@muneer correctly indicates it is possible, but it may not be advisable. What is your goal? Are you trying to create some sort of array or data-bound form? Depending on the use, there may be a thunkable component better suited to your purpose.

---

<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 13, 2021, 6:10pm UTC](https://community.thunkable.com/t/how-to-assign-a-unique-variable-to-dynamically-created-component/1047889/4 "2021-01-13T18:10:26Z")

</div>

I agree with @drted. I was going to say that I’m always confused about why people would want to use dynamically-named variables but there may be a use case I just haven’t come across.

A list, data source or firebase is almost always going to be more manageable and efficient.

---

<div class="post-metadata">

### Author: ![sp72979rdrlbc](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/sp72979rdrlbc/32/94224_2.png) [@sp72979rdrlbc](https://community.thunkable.com/u/sp72979rdrlbc)
#### Post date: [January 13, 2021, 10:42pm UTC](https://community.thunkable.com/t/how-to-assign-a-unique-variable-to-dynamically-created-component/1047889/5 "2021-01-13T22:42:34Z")

</div>

@drted and @tatiang

Hi! so in more detail what I’m trying to do is this:

Page 1: So on the first page, the user can make buttons dynamically and that button is stored in a variable with a unique name.

Page 2: when one is clicked they go to this page where the variable of the dynamically created button is referenced, a timer starts on that page and when the user presses stop on the timer, the time of the timer when it was stopped, is set to the text of the clicked button on the first page.

Would a data source of firebase be better in this case?

---

<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 14, 2021, 5:18pm UTC](https://community.thunkable.com/t/how-to-assign-a-unique-variable-to-dynamically-created-component/1047889/6 "2021-01-14T17:18:06Z")

</div>

No, I think you’re probably going about it right. There are multiple ways to do this but using the blocks @muneer provided should work.

---

<div class="post-metadata">

### Author: ![sp72979rdrlbc](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/sp72979rdrlbc/32/94224_2.png) [@sp72979rdrlbc](https://community.thunkable.com/u/sp72979rdrlbc)
#### Post date: [January 15, 2021, 3:00am UTC](https://community.thunkable.com/t/how-to-assign-a-unique-variable-to-dynamically-created-component/1047889/7 "2021-01-15T03:00:16Z")

</div>

Hi @muneer,

Thanks for all your help! I think I followed your instructions but I think I didn’t do it right here is what it looks like:

 ![Screenshot 2021-01-14 at 6.52.14 PM (1)](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/f/4f2d4bf0b8295787a7f238f7b59f353ecb32bbd8.png)

And I got this for the variable names:  
 ![Screenshot 2021-01-14 at 6.56.18 PM (1)](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/3/230943792af35d9bebd8d75012e33da3e51423e7.png)

I did something wrong?

---

<div class="post-metadata">

### Author: ![luv.ak.tech](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/luv.ak.tech/32/104896_2.png) [@luv.ak.tech](https://community.thunkable.com/u/luv.ak.tech)
#### Post date: [January 15, 2021, 3:48am UTC](https://community.thunkable.com/t/how-to-assign-a-unique-variable-to-dynamically-created-component/1047889/8 "2021-01-15T03:48:14Z")

</div>

what you want the text to be?

---

<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 15, 2021, 4:40am UTC](https://community.thunkable.com/t/how-to-assign-a-unique-variable-to-dynamically-created-component/1047889/9 "2021-01-15T04:40:37Z")

</div>

The component block stores the component’s ID. The ID is a long string of characters like in the screenshot you posted above. You need the button component’s Text. So your blocks would be set app variable “Time” to [get button [component] text].

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [January 15, 2021, 7:08am UTC](https://community.thunkable.com/t/how-to-assign-a-unique-variable-to-dynamically-created-component/1047889/10 "2021-01-15T07:08:14Z")

</div>

As @tatiang described, Thunkable uses an internal ID for every component you create. For example, right click on any component and you will see a good example of internal IDs of Thunkable in the pop-up menu.  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/5/25e31671e2261809e0facf5330702d86acef5f10.png)

Another issue is the names you assign to the buttons. I take it you are creating a variable called “Time” in this variable you want to store a text followed by a number. so you need to do something like this  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/c/9/c96c27b9d41bdead2f32a190944eab6e95a93bc7.png)  
Which, if the text of the button is “Car” then the variable will have the text “Car1”. The way you have done it would yield to trying to increment the the value by 1.

---

<div class="post-metadata">

### Author: ![sp72979rdrlbc](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/sp72979rdrlbc/32/94224_2.png) [@sp72979rdrlbc](https://community.thunkable.com/u/sp72979rdrlbc)
#### Post date: [January 15, 2021, 11:27pm UTC](https://community.thunkable.com/t/how-to-assign-a-unique-variable-to-dynamically-created-component/1047889/11 "2021-01-15T23:27:18Z")

</div>

Thank you!

---

<div class="post-metadata">

### Author: ![sp72979rdrlbc](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/sp72979rdrlbc/32/94224_2.png) [@sp72979rdrlbc](https://community.thunkable.com/u/sp72979rdrlbc)
#### Post date: [January 16, 2021, 12:47am UTC](https://community.thunkable.com/t/how-to-assign-a-unique-variable-to-dynamically-created-component/1047889/12 "2021-01-16T00:47:33Z")

</div>

Thank you!  
One question: how would I reference a variable that was created?

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [January 16, 2021, 6:37am UTC](https://community.thunkable.com/t/how-to-assign-a-unique-variable-to-dynamically-created-component/1047889/13 "2021-01-16T06:37:37Z")

</div>

Just to clarify, let’s use a sample from the blocks you created

 ![Screenshot_20210116_093211](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/e/3/e3265ba5f69cae775dc692766c399d98699bb2fc.jpeg)

This does not mean to get the value of variable “Time” but it actually means you are getting the value of the variable mentioned in variable “Time”.

So if the newly created variable is called “var1” which is referenced by the dynamic variable “Time” then your block will obtain the value of “var1”.

Hope this clarifies the situation.

---

<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, 1:30pm UTC](https://community.thunkable.com/t/how-to-assign-a-unique-variable-to-dynamically-created-component/1047889/14 "2024-11-08T13:30:48Z")

</div>


