Are you trying to run a function with the loop or navigate to a screen?
Is it a loop or an IF condition?
Are you trying to run a function with the loop or navigate to a screen?
Is it a loop or an IF condition?
Run a function
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.
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?
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.
Yes just changing the colors is very simple, my real world example is the following
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?
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.
Demo project: Thunkable
(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.
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
and select the screen funcvars
here are some screenshots:
this is exciting!
See the updated project
https://x.thunkable.com/copy/e2d3db5e47dfa82c91364330747a0582
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.
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.
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.
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
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
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.
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.
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.
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.
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.
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.