# We need local variables

**URL:** https://community.thunkable.com/t/we-need-local-variables/431105
**Category:** Questions about Thunkable X
**Created:** [January 28, 2020, 8:52am UTC](https://community.thunkable.com/t/we-need-local-variables/431105 "2020-01-28T08:52:52Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![rollke](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/rollke/32/14413_2.png) [@rollke](https://community.thunkable.com/u/rollke)
#### Post date: [January 28, 2020, 8:52am UTC](https://community.thunkable.com/t/we-need-local-variables/431105/1 "2020-01-28T08:52:52Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)
#### Post date: [January 28, 2020, 12:06pm UTC](https://community.thunkable.com/t/we-need-local-variables/431105/2 "2020-01-28T12:06:14Z")

</div>

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.

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

---

<div class="post-metadata">

### Author: ![rollke](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/rollke/32/14413_2.png) [@rollke](https://community.thunkable.com/u/rollke)
#### Post date: [January 28, 2020, 12:24pm UTC](https://community.thunkable.com/t/we-need-local-variables/431105/3 "2020-01-28T12:24:10Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![domhnallohanlon](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/domhnallohanlon/32/29554_2.png) [@domhnallohanlon](https://community.thunkable.com/u/domhnallohanlon)
#### Post date: [January 28, 2020, 12:25pm UTC](https://community.thunkable.com/t/we-need-local-variables/431105/4 "2020-01-28T12:25:47Z")

</div>

> [@rollke](#):
>
> These could be used for temporary use in the function only and are not accessible outside the function.

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

---

<div class="post-metadata">

### Author: ![rollke](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/rollke/32/14413_2.png) [@rollke](https://community.thunkable.com/u/rollke)
#### Post date: [January 28, 2020, 12:33pm UTC](https://community.thunkable.com/t/we-need-local-variables/431105/5 "2020-01-28T12:33:57Z")

</div>

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

---

<div class="post-metadata">

### Author: ![domhnallohanlon](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/domhnallohanlon/32/29554_2.png) [@domhnallohanlon](https://community.thunkable.com/u/domhnallohanlon)
#### Post date: [January 28, 2020, 12:40pm UTC](https://community.thunkable.com/t/we-need-local-variables/431105/6 "2020-01-28T12:40:47Z")

</div>

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?

 ![temp_variables](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/a/fae1cfd280125d0fac4a1887efba60a343c1224d.png)

---

<div class="post-metadata">

### Author: ![rollke](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/rollke/32/14413_2.png) [@rollke](https://community.thunkable.com/u/rollke)
#### Post date: [January 28, 2020, 2:18pm UTC](https://community.thunkable.com/t/we-need-local-variables/431105/7 "2020-01-28T14:18:39Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![artificialdama4u](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@artificialdama4u](https://community.thunkable.com/u/artificialdama4u)
#### Post date: [April 30, 2020, 10:06pm UTC](https://community.thunkable.com/t/we-need-local-variables/431105/8 "2020-04-30T22:06:25Z")

</div>

@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

---

<div class="post-metadata">

### Author: ![artificialdama4u](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@artificialdama4u](https://community.thunkable.com/u/artificialdama4u)
#### Post date: [April 30, 2020, 10:10pm UTC](https://community.thunkable.com/t/we-need-local-variables/431105/9 "2020-04-30T22:10:29Z")

</div>

@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

---

<div class="post-metadata">

### Author: ![domhnallohanlon](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/domhnallohanlon/32/29554_2.png) [@domhnallohanlon](https://community.thunkable.com/u/domhnallohanlon)
#### Post date: [May 1, 2020, 9:51am UTC](https://community.thunkable.com/t/we-need-local-variables/431105/10 "2020-05-01T09:51:08Z")

</div>

> [@artificialdama4u](#):
>
> I could be happy if just I could put “temp” directly as the return value

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

---

<div class="post-metadata">

### Author: ![artificialdama4u](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@artificialdama4u](https://community.thunkable.com/u/artificialdama4u)
#### Post date: [May 1, 2020, 10:26am UTC](https://community.thunkable.com/t/we-need-local-variables/431105/11 "2020-05-01T10:26:43Z")

</div>

I tried. I couldn’t. 😕 A pity.

---

<div class="post-metadata">

### Author: ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)
#### Post date: [May 1, 2020, 10:30am UTC](https://community.thunkable.com/t/we-need-local-variables/431105/12 "2020-05-01T10:30:07Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![artificialdama4u](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@artificialdama4u](https://community.thunkable.com/u/artificialdama4u)
#### Post date: [May 1, 2020, 11:06am UTC](https://community.thunkable.com/t/we-need-local-variables/431105/13 "2020-05-01T11:06:09Z")

</div>

There we go then…  
[https://x.thunkable.com/copy/fde1bf6ee035a5d4ac2b97350e8b0673](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.

---

<div class="post-metadata">

### Author: ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)
#### Post date: [May 1, 2020, 11:22am UTC](https://community.thunkable.com/t/we-need-local-variables/431105/14 "2020-05-01T11:22:18Z")

</div>

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

---

<div class="post-metadata">

### Author: ![artificialdama4u](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@artificialdama4u](https://community.thunkable.com/u/artificialdama4u)
#### Post date: [May 1, 2020, 11:55am UTC](https://community.thunkable.com/t/we-need-local-variables/431105/15 "2020-05-01T11:55:59Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)
#### Post date: [May 1, 2020, 12:04pm UTC](https://community.thunkable.com/t/we-need-local-variables/431105/16 "2020-05-01T12:04:41Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![henrikhngj5](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/henrikhngj5/32/67710_2.png) [@henrikhngj5](https://community.thunkable.com/u/henrikhngj5)
#### Post date: [May 1, 2020, 3:32pm UTC](https://community.thunkable.com/t/we-need-local-variables/431105/17 "2020-05-01T15:32:45Z")

</div>

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…

---

<div class="post-metadata">

### Author: ![artificialdama4u](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@artificialdama4u](https://community.thunkable.com/u/artificialdama4u)
#### Post date: [May 2, 2020, 11:04pm UTC](https://community.thunkable.com/t/we-need-local-variables/431105/18 "2020-05-02T23:04:59Z")

</div>

@jared I can add more information to this “bug?”  
see [https://x.thunkable.com/copy/1f9fde7fadb0e6726882cd12dc7606f4](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?

---

<div class="post-metadata">

### Author: ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)
#### Post date: [May 2, 2020, 11:27pm UTC](https://community.thunkable.com/t/we-need-local-variables/431105/19 "2020-05-02T23:27:45Z")

</div>

post issues/bugs here

> **[Build software better, together](https://github.com/thunkable/thunkable-issues/issues/new?template=bug_report.md)**
>
> GitHub is where people build software. More than 83 million people use GitHub to discover, fork, and contribute to over 200 million projects.

---

<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, 11:29am UTC](https://community.thunkable.com/t/we-need-local-variables/431105/20 "2024-11-08T11:29:31Z")

</div>


