We need local variables

The situation:
You create a function with parameters and a result.
Inside the function block you have to calculate several values by help variables. It is a logic catastrophe to use global (app) variables for this.
And in bigger projects you loose overview.

Of course you could implement additional parameters to use them as local variables. But that is not a proper solution.
Or you can construct a count loop that you do not use and use the names of the loop variables. But is that a solution.
What do you think?

So we urgently need local variables!

2 Likes

Is this what you mean! There are “helper” or local variables to be used in the function blocks. Try clicking the settings wheel on the function blocks.

1 Like

Parameters (input) in functions are local variables. That is correct.
But when you create them with the function, you have pass values to them when using the function.

What I mean, are local variable to be created inside (!) the function. These could be used for temporary use in the function only and are not accessible outside the function.

1 Like

That’s the whole point of a local variable, no?

Yes, but we cannot create them inside functions, no?

Ah, I get you now.

No, that’s not possible - at least with the current set of variables.

Here’s a (slightly ugly) work around that might work for you?

Thank You!

“Open Parameters” in function call look rather strange.

As a teacher and author of a books on app development I have some “problems” with that “solution”.

I want to teach the use of functions (with local variable) in Thunkable X properly and in my publications. I cannot use a “slightly ugly” workaround.

Could we expect local variable in future updates of Thunkable X?
I mean near future.

2 Likes

@domhnallohanlon domhnallohanlon, jared idea and your idea of using parameters as local varibles… I agree

well [domhnallohanlon] your work around it’s quite nice but to do what rollke and many other people need the question is: why I need an app or stored variable to send the result?

I mean in your work around I could be happy if just I could put “temp” directly as the return value

that is enough, but it’s not working (at least not working for me)

POST1: I have been testing this and I think we can asume the parameter variables are READ ONLY and because of that you can not use them to operate or to return a result

@jared your idea of using parameters as local varibles… I agree

but in your blocks you can’t use any of that “helper” variables to set the return value
the question is: why I need an app or stored variable to send the result (return) value?

I mean in your work around I could be happy if just I could put “_add as manu as you need” directly as the return value

that would be enough, but it’s not working (at least not working for me)

POST1: I have been testing this and I think we can asume the parameter variables are READ ONLY and because of that you can not use them to operate or to return a result

I think you probably can put temp as the return value here, no?

I tried. I couldn’t. :confused: A pity.

I do what you are trying al the time. Can you share a removable project that only shows the issue you are talking about or a share link to your app.

You should be able to return the temp variable with no issue.

1 Like

There we go then…
https://x.thunkable.com/copy/fde1bf6ee035a5d4ac2b97350e8b0673

As you will see the value is not arriving to the button text…

POST: second parameter in the join statement should be “str_b” but anyway you can see the issue.

this is basically the same project.
but it works?
https://x.thunkable.com/copy/9a85b0a91e0d5654f151a0c336571e88

1 Like

O M G !!!
1st: thanks 4 your time, really
2nd: now I’m super confused… it works in the Screen1.Opens but not if fired from a Button1.Click. What a headache!

Maybe someone else can chime in. If this is in fact a repeatable bug, it should be reported to github.

local variables can return a value in typical JavaScript/react. I would imagine them to work the same here.

Hi rollke,

I Totally agree with you, the app variables solution will soon lead to a complete mess.

My project is reaching a critical size and I am getting more and more anxious about using variables, leading me to create more variables which further makes me loose any kind of overview.

The fact that we have no scope concept and that everything is live everywhere is a limitator to how far you can take thunkable. If thunkable want to grow out of it’s teens we need to be able to scope variables…

1 Like

@jared I can add more information to this “bug?”
see https://x.thunkable.com/copy/1f9fde7fadb0e6726882cd12dc7606f4

try to execute it just as it is
then try deleting the “wait 3 seconds” block

so… we see something is wrong or it’s too slow in the variable value
should we report this? do you know how to do that?

post issues/bugs here