# Functions with dropdown for j i list or variables

**URL:** <https://community.thunkable.com/t/functions-with-dropdown-for-j-i-list-or-variables/1663537>\
**Category:** Questions about Thunkable X\
**Tags:** variables, list, function\
**Created:** [January 1, 2022, 1:32am UTC](https://community.thunkable.com/t/functions-with-dropdown-for-j-i-list-or-variables/1663537 "2022-01-01T01:32:43Z")\
**Posts on this page:** 20\
**Page:** 2

<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 3, 2022, 1:31am UTC](https://community.thunkable.com/t/functions-with-dropdown-for-j-i-list-or-variables/1663537/21 "2022-01-03T01:31:42Z")

</div>

> [@overshield](#):
>
> only that specific color Screen Fx should run

Are you trying to run a function with the loop or navigate to a screen?

Is it a loop or an IF condition?

---

<div class="post-metadata">

**Author:** ![overshield](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@overshield](https://community.thunkable.com/u/overshield)\
**Post date:** [January 3, 2022, 1:36am UTC](https://community.thunkable.com/t/functions-with-dropdown-for-j-i-list-or-variables/1663537/22 "2022-01-03T01:36:59Z")

</div>

Run a function

---

<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 3, 2022, 1:43am UTC](https://community.thunkable.com/t/functions-with-dropdown-for-j-i-list-or-variables/1663537/23 "2022-01-03T01:43:17Z")

</div>

I showed you **two** ways of how to run a function using the name of the function inside a `for each item` loop. One using an action function and one using a return function.

Of course you could complicate the situation further and make two lists, one for colours and another one for functions and you loop through the colours but run the function using the index of the position of the color.

---

<div class="post-metadata">

**Author:** ![overshield](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@overshield](https://community.thunkable.com/u/overshield)\
**Post date:** [January 3, 2022, 3:50am UTC](https://community.thunkable.com/t/functions-with-dropdown-for-j-i-list-or-variables/1663537/24 "2022-01-03T03:50:44Z")

</div>

When I click on your buttons, it cycles through **all 3** of the functions. I am not asking for it to do that.  
I’m asking for 3 different conditionals (in my example the RGB buttons) and depending on the condition, it would grab the appropriate function, but only a single function, I don’t want it to run all the functions.

Like in my example, I want the blue button to cause the screen to turn blue, but not all three colors of red, green, and blue… just blue alone.

I think @tatiang is on to something seeing what order they’re in, but that would mean the functions must be in a certain order, and the buttons must be in the same order I believe, which kinda gets rid of the whole purpose, bc that’s not much different than:

if blue button, then blue function  
else if red button, then red function  
else if green button, then green function

I don’t want to have to add on to the else if every time I make a function. I just want to add to the list of functions and it grab a **single** function

I see you went to the trouble of making that project, but could you make one that does what I have described above?

---

<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 3, 2022, 3:59am UTC](https://community.thunkable.com/t/functions-with-dropdown-for-j-i-list-or-variables/1663537/25 "2022-01-03T03:59:47Z")

</div>

It feels like you’re overcomplicating things. But it’s not clear to me because you’ve provided a very simple example that could be done with a single block (setting RGB values) and doesn’t really require functions.

Would it work to have a function (with an input variable value) that contains an if/elseif/else block that runs various commands based on the input value? Then the buttons would just set the input value and call the function. It seems like that’s what you’re going for.

---

<div class="post-metadata">

**Author:** ![overshield](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@overshield](https://community.thunkable.com/u/overshield)\
**Post date:** [January 3, 2022, 4:09am UTC](https://community.thunkable.com/t/functions-with-dropdown-for-j-i-list-or-variables/1663537/26 "2022-01-03T04:09:02Z")

</div>

Yes just changing the colors is very simple, my real world example is the following

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/4/74e0cfbc48735adda29beb14e0eb0bea5a67fe2a.png)  
Regardless of the simplicity though.

I don’t want to have to add to the bottom of the if else block every time I want to add a new function.  
I just want a for each item j block to somewhat call the function by name…

So if the user is on the Preference Page, run the Set Preference function,  
If the user is on the Name Page, run the Set Name function

If I can do that, then I can just add a function to my list and be done with it.

For each item j in list of functions  
If user is on page j, execute function j

Can you make a simple project like you’re describing and share it or post a SS of it?

---

<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 3, 2022, 4:24am UTC](https://community.thunkable.com/t/functions-with-dropdown-for-j-i-list-or-variables/1663537/27 "2022-01-03T04:24:12Z")

</div>

It’s really very similar to what you just posted. The only difference is that it calls a single function and uses `app variable Current Page Title` as the input value. I don’t think you’re going to be happy with it, though. No matter what, it still requires adding an elseif block each time you add new functionality.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/1/8/18922f99fd6745d7a192a8f7b1a602a621126dd0.png)

Demo project: [Thunkable](https://x.thunkable.com/copy/d3f0b3ebb482e3f5d340fa2ff2d725fb)  
(See screen with your username)

I get what you’re asking for but it’s not currently possible. So you either use a workaround or you add it as a feature request.

---

<div class="post-metadata">

**Author:** ![manyone](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@manyone](https://community.thunkable.com/u/manyone)\
**Post date:** [January 3, 2022, 7:08am UTC](https://community.thunkable.com/t/functions-with-dropdown-for-j-i-list-or-variables/1663537/28 "2022-01-03T07:08:08Z")

</div>

surprise! surprise! thunkable can handle function variables via lists! in other words, you can pass a function as a parameter - no more nested or cascading if … then … else blocks!

click this project  
[https://x.thunkable.com/copy/1df4f43c796e192c45263930695e0ad2](https://x.thunkable.com/copy/1df4f43c796e192c45263930695e0ad2)  
and select the screen **funcvars**

here are some screenshots:

 ![funcvars1](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/a/9/a9a00711727322f3f190fbd1406f15ef585e3b61.jpeg)  
 ![funcvars2](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/a/d/ad9e69b99fceec76d06f7f91b8f13f874634d783.jpeg)

this is exciting!

---

<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 3, 2022, 2:10pm UTC](https://community.thunkable.com/t/functions-with-dropdown-for-j-i-list-or-variables/1663537/29 "2022-01-03T14:10:41Z")

</div>

See the updated project  
[https://x.thunkable.com/copy/e2d3db5e47dfa82c91364330747a0582](https://x.thunkable.com/copy/e2d3db5e47dfa82c91364330747a0582)

---

<div class="post-metadata">

**Author:** ![overshield](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@overshield](https://community.thunkable.com/u/overshield)\
**Post date:** [January 3, 2022, 3:17pm UTC](https://community.thunkable.com/t/functions-with-dropdown-for-j-i-list-or-variables/1663537/30 "2022-01-03T15:17:27Z")

</div>

This is great @manyone and @muneer

Are you able to make the function make changes to components like this when you call on the function to execute?  
I tried doing this but it didn’t work so maybe I’m missing a step or 2.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/a/1/a15ce065343b9c65105c17f4863b127388168f1a.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 3, 2022, 3:21pm UTC](https://community.thunkable.com/t/functions-with-dropdown-for-j-i-list-or-variables/1663537/31 "2022-01-03T15:21:15Z")

</div>

> [@overshield](#):
>
> function make changes to components like

My function actually changes the `Text` property of a `Label` and it will do any other changes to components with one something to have in mind.

Functions do not work **across screens**. Functions can only be triggered from the active screen and can only change properties of components to the active screen.

---

<div class="post-metadata">

**Author:** ![overshield](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@overshield](https://community.thunkable.com/u/overshield)\
**Post date:** [January 3, 2022, 3:23pm UTC](https://community.thunkable.com/t/functions-with-dropdown-for-j-i-list-or-variables/1663537/32 "2022-01-03T15:23:31Z")

</div>

I’m staying in the same screen, but in my case I’m trying to make it create a new button when the function executes but that isn’t working.

I want to be able to edit more than a single component. It needs to actually execute the function, not just return a single value from it.

---

<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 3, 2022, 3:37pm UTC](https://community.thunkable.com/t/functions-with-dropdown-for-j-i-list-or-variables/1663537/33 "2022-01-03T15:37:19Z")

</div>

This is the code I made to the `set Country` Function  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/8/884a67f0676ad056342ef8cb9726a75cfa141fea.png)

This is the output

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/8/483e69184d14703983e4865c83193649441173ea.png)

---

<div class="post-metadata">

**Author:** ![overshield](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@overshield](https://community.thunkable.com/u/overshield)\
**Post date:** [January 3, 2022, 3:47pm UTC](https://community.thunkable.com/t/functions-with-dropdown-for-j-i-list-or-variables/1663537/34 "2022-01-03T15:47:00Z")

</div>

And this occurs for you whenever you tap the ‘Country’ item from the list?

I changed a 2nd function and without even touching an item from the list I get the following output  
I don’t want both buttons to be created, only one should be created at a time.  
When I tap ‘Country’ the set Country button should only then be created, same goes for ABCD status

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/9/99cbfb8c06ad8977128ef16a645754f10199a2d9.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 3, 2022, 4:44pm UTC](https://community.thunkable.com/t/functions-with-dropdown-for-j-i-list-or-variables/1663537/35 "2022-01-03T16:44:00Z")

</div>

> [@overshield](#):
>
> I don’t want both buttons to be created

Functions are run when assigned and because we create a list of functions we are actually executing them.

You can simply create a control variable that is set to **False** as a start and in the function check to see that this control variable is **True** before creating any components. then after you select an option from the list set the control variable to **True**.

Example  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/7/775dddfff1615b60c88a213eff8a3284c423db52.png)

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/8/784e36ebb568e8a8d0b7586d4ec21923bcc6e2d4.png)

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/b/9bbdac3f8d931729276ace7a079b4796bb44c282.png)

---

<div class="post-metadata">

**Author:** ![overshield](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@overshield](https://community.thunkable.com/u/overshield)\
**Post date:** [January 3, 2022, 8:12pm UTC](https://community.thunkable.com/t/functions-with-dropdown-for-j-i-list-or-variables/1663537/36 "2022-01-03T20:12:41Z")

</div>

After going through all of this I think it’s just going to be more efficient for now to add to the if, else if, if block.

---

<div class="post-metadata">

**Author:** ![overshield](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@overshield](https://community.thunkable.com/u/overshield)\
**Post date:** [January 3, 2022, 8:45pm UTC](https://community.thunkable.com/t/functions-with-dropdown-for-j-i-list-or-variables/1663537/37 "2022-01-03T20:45:39Z")

</div>

It really needs to look exactly like I have below, with the component I made the red arrow to it, which I made up…

It doesn’t need to have wait functions, doesn’t need the indices, doesn’t need the if, else if, else block, doesn’t need a list viewer, doesn’t need all the other suggested stuff, just needs the ability to choose a function from a list. **One** function, not All functions, and execute the contents inside that one function.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/5/45d683553247f20ef4275dc06e7b6fcc11f68df8.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 4, 2022, 1:30am UTC](https://community.thunkable.com/t/functions-with-dropdown-for-j-i-list-or-variables/1663537/38 "2022-01-04T01:30:40Z")

</div>

The function that has the large arrow is logically **incorrect**.

You are trying to loop through a list of **functions** which will cause these functions to execute one after the other.

Further more, you are testing for an impossible condition inside the loop. You are trying to test if the **function** is equals to a **text**. This condition will not yield true and therefore the action inside the condition will never be executed.

---

<div class="post-metadata">

**Author:** ![overshield](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@overshield](https://community.thunkable.com/u/overshield)\
**Post date:** [January 4, 2022, 2:03am UTC](https://community.thunkable.com/t/functions-with-dropdown-for-j-i-list-or-variables/1663537/39 "2022-01-04T02:03:02Z")

</div>

> [@muneer](#):
>
> You are trying to loop through a list of **functions** which will cause these functions to execute one after the other

Yes this is inherently the problem, it shouldn’t execute them just because they’re added to a list or looped, it should only execute when the conditions I set are met, just like putting an if statement inside a for item j block.

> [@muneer](#):
>
> Further more, you are testing for an impossible condition inside the loop. You are trying to test if the **function** is equals to a **text**. This condition will not yield true and therefore the action inside the condition will never be executed.

Right I’m wanting a way to call the function by name, that would be the reason for the dropdown that I provided in my very first post. There would exist a list of functions in that drop down, a list that I have created so it’s not every single function I’ve created, just the ones I’ve added to that list.

---

<div class="post-metadata">

**Author:** ![manyone](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@manyone](https://community.thunkable.com/u/manyone)\
**Post date:** [January 4, 2022, 3:10am UTC](https://community.thunkable.com/t/functions-with-dropdown-for-j-i-list-or-variables/1663537/40 "2022-01-04T03:10:59Z")

</div>

> [@overshield](#):
>
> it should only execute when the conditions I set are met, just like putting an if statement inside a for item j block.

unfortunately, you have to code it exactly the way you said it: if you want something done conditionally, you have to enclose it in an if-block.

there is no “execute function j” (where j is a variable) in thunkable yet. thunkable can only handle “hardcoded” function calls. you should submit your idea as a feature requests because it’s a good idea.

[Previous page](https://community.thunkable.com/t/functions-with-dropdown-for-j-i-list-or-variables/1663537.md?page=1)

[Next page](https://community.thunkable.com/t/functions-with-dropdown-for-j-i-list-or-variables/1663537.md?page=3)
