How to create additional local variables inside functions?

Hi,

due to the initialization of variable it is only possible to create app variables, and storage or cloud variables. All of them are global to the app.

But what, if I want to create local variables (e.g. help variables) inside a function. I do not mean the parameters, they are local. I mean additional local variables.

Where is this block from Thunkable classic gone to x.thunkable?
Or is there a workaround for x.thunkable?
44

Hi,

I have long made the request for these blocks, but no information about when they will appear, or if they appear at all I do not have.

As a workaround, you can do this: call the function block parameters prefixed with _ (as it was done in Javascript before the let declarations), and when the function set its value to undefined.

%D0%B8%D0%B7%D0%BE%D0%B1%D1%80%D0%B0%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5

2 Likes

Thank you actech.
But the problem is, that there is only the initialize app block for variable definition.
When teaching this to students I cannot use a workaround like yours, because they cannot initialize local variables within the function block. But for teaching computer science in a class it is important to know the difference between local and global data.

I agree with you. While using Thunkable X is not possible to show the local variables.

Hi Thunkers! :wave:

Using a lot App Variables causes a lag :confused: Many of us have experienced it…
So, can the Thunkable Team add a new variable type like local variable -

image

When I need to use variables for only a block like -

image
I need to use image

Using App Variables causes a lag :confused: Many of us have experienced it…

I will be waiting :slightly_smiling_face:
Thanks! :tada:

P.S. This request was also made by @actech once in a post :+1:

3 Likes

That‘s exactly what I want, too (see my post some days ago)

1 Like

Many Thunkers want it, there are various posts which say it.

Thanks! :blush:

Thanks for the feedback @rollke, @kartik14 and @actech

We definitely want to keep improving the platform, but I’m not aware of any plans to add in local variables.


@rollke is there anything that the current offering of variables does not allow you to do? i.e. is the lack of local variables preventing your from completing some important aspect of your app at the moment?


ok - this is a fair point!


I think what you’re really asking for here @kartik14 is for faster variables, no? :joy:

@domhnallohanlon,

you caught me! :joy: :sweat_smile:

Since App Variables make the Platform lag, I requested for local variables :smile:
If app variables can improve, there’s no need of local variables for me :smile:

Thanks! :blush:

1 Like

Thanks for clarifying @kartik14.

As mentioned above, we’re keen to keep improving the platform but at this stage have to prioritise the features that are preventing users from completing their projects.

If the absence of a component/property is not blocking users from building their app then it gets added to the queue, but with a lower priority.

Hope that makes sense.

1 Like

Yep, this makes complete sense, priorities first! :blush:

Thanks for your time! :blush:

Hi,

Imitation of a local variable. To create a local variable, you must create a function parameter with the same name as the variable block from the function parameter.

%D0%B8%D0%B7%D0%BE%D0%B1%D1%80%D0%B0%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5

1 Like

Thank you!

But would you really teach students to create and use local variables?

1 Like

No, the method I showed is called like this - turning a global variable from a parameter of function into a local variable. Unfortunately, this is the maximum that can be achieved from Thunkable X.

If student training is based on Thunkable X, then the teacher will often have to say that this or that mechanism of work is specific to the Thunkable X platform and in programming languages it works differently or there is no such concept at all.

1 Like