Get component name

Hi. Is there a way to programatically get the name of a component?
Example: User clicks on a button and the name of that button would be a variable value.
Thanks

I was actually going to suggest a component labelling option, but I find setting background picture resize mode to the value. Or some sort of variable of the component that you arenā€™t using. Of course if you are using that value then your other options would be to set things like text (if the text is invisible) or set background picture if there is no picture.

For the information above, I assumed you are using buttons.

(edit)

For me, Thunkable keeps the component settings default if the settings you inserted arenā€™t to the format required. So the background picture resize mode could = ā€œoption-1ā€.

1 Like

Edit: oops! You want the name. Hmm, no, I donā€™t think so. I read this too quickly. Sorry!

You can get the button ID. This topic explains how:

Itā€™s a little more detailed than you might need so hereā€™s a simple way to get that info:

Screen Shot 2020-01-11 at 1.28.55 PM

1 Like

Hi, @yosik! :wave:

I have a nice idea for you. When you rename your component, set the new name in the background picture box as well. Like this -

image

So, when the button gets clicked, you would get the component name by this -

This will work, because in our case, a buttonā€™s background picture is simply itā€™s component name.

Hope this helps you! :slightly_smiling_face:
Thanks! :blush:

1 Like

Thanks for responding.
@kartik14, your idea will work only if ALL buttons use the same image. In my case, each button has a different imageā€¦But I am keepipng your solution for other projects.
@eoinparkinson, this would work, but as far as dev effort is concerned, it comes out the same as having a different block for each button. In addition, although it is a good workaround, it is not good programming practice. Again, Thank you very much for the thought.

Thunkable Team. I think this is a needed feature and ā€œComponent Nameā€ should be added as a property to all components.

Cheers,
Yossi

1 Like

Hi,

Example of working with a component name (Spreadsheet is used to get a nice name for the name of a new property)

ŠøŠ·Š¾Š±Ń€Š°Š¶ŠµŠ½ŠøŠµ

1 Like

Hi @actech ,
I think you misunderstood me.
I am not looking for a way to write text on a Button, I am looking for a way to get the NAME of a button and use it and this is because I do not have any text on my buttons, just images.
TY
Yossi

If you donā€™t have texts on your images, set the text as transparent, and set the ā€œNameā€ of the button on the text.

Edit because submitted before end xD : Youā€™re asking for a solution to what you want but there is no existing one. So youā€™re forced to do it with workarounds. Also, I didnā€™t get what you meant by ā€œitā€™s the same as having a different block for each buttonā€, you just get the any button clicked event, get the text of the component getting clicked, and push that text into a variable, it looks exactly like what you want, expect if I misunderstood something

1 Like

In the example below I get the button name and use it. But to do this, you must first explicitly set the name for the button, as you understand.

Other way

ŠøŠ·Š¾Š±Ń€Š°Š¶ŠµŠ½ŠøŠµ

3 Likes

@AcrobatEpee and @actech, Thank you. Yes, both of your solutions are working.
Appreciate the effort and the answers.
:grinning:

But @actech, in the second example, arenā€™t you just created a list with properties for each button name? They arenā€™t actually associated with particular buttons, are they? So when you need to retrieve a specific button name, you still need to know the button # and then match it to the list element/index.

In the second example, a list of pairs is created, where the component ID is used as the key, and an arbitrary name is used as the value. Therefore, the ID is associated with the name, but the name is not stored in the component. When working with components, we can easily find out its ID, and then use the list of keys to get a predefined name for it. If you did not specify a name for a button, then naturally you cannot use a name for such a button. Similarly, the first option will not work if the property for saving the name was not initially created.

Thanks for explaining. I didnā€™t realize you were getting the component ID.

Access to a component by name is used in text programming and this is really more convenient than ID, but I believe that we need not just the name of the component, but the ability to use this name to access components located on another screen. I made such a request to the developers, but I do not think that it will ever be realized.

2 Likes