Variables initialization behaviour

if true create row

I’m going crazy, this works only the first time I test it and then stops working, I tried different iterations of it and they all follow the same destiny!

The starting trigger is anybutton click and the variable is initialized as false

Is there something I’m not getting?

A good way to trace the issue is to place a vibration block in every step in turns and try to see where the logic fails. Give it a shot.


I second this. I use a debug label :label: with some message I decided like “not broke yet”. Then I place it sequentially through the sequence that is causing crashes until I find the point that it doesn’t show

1 Like

But where you initialize the variable is important. You didn’t show the whole set of blocks but if you are initializing the variable outside of these blocks, this set of rules will only run once because you’ve changed the variable to true at the end of the If block.

Can you post the full set of blocks including the initialization?

1 Like

I did and it’s the if part that just doesn’t work, without it the commands respond

I initialize the variable as false and the sequence of blocks starts with a anybutton click, I don’t get what you are asking I’m sorry

print the value of that variable before that if block. make sure it holds the value you think it should.

Can you share this bug so we may see it in action? I can’t recreate this.

Ok I trust and right now I can’t share it, I also preferred a different, less elegant but more resources preserving solution so it’s not important to understand where my mistake is.

Thank you all

Sorry if I wasn’t clear. Post a screenshot without the top cut off, showing the any button click part.

If there is ONLY an any button click block missing from the screenshot then I would expect it to NOT work, just as you described in the first post.

Because your logic is basically this:

Set variable to false

If button is clicked AND variable is false

Set variable to true

If button is clicked AND variable is false [this will never trigger]

1 Like


As soon as I change the code, it works, but as I load again the app, it doesn’t work anymore!

These solutions both work, it’s just that they work only the first time I test them! aaargh:

if false

if true

Is there a section with the known bugs of the platform so that we don’t waste our time?

Can you set the var value after the then do?

Same result.
I’ve made different tests now, looks like the initialization of the variable doesn’t really initialize it, when I start the app, the variable is already true, or whatever value i set it in a previous run of the test app.
The only way I can be sure for it to work is that I set the value of the variable to false when the screen starts.

I tried to wipe the cache of the companion app, force close it and nothing, still makes the bug.

It might be a problem of my specific app since I often clone the initializations of variables, maybe something went wrong at a certain point, but I made a test initializing a new variable with the same results.

I also see that it takes sometimes many minutes to update my companion app testing, like now, it’s been almost 10 minutes that I’m trying to refresh to see the new changes but the companion app doesn’t update

have you tried to adding the ‘set var’ block inside ‘when screen opens’? i

@jared Event I use the same approach…
What I do is, place labels everywhere; Like ‘reached calling all rows’ > ‘got all rows’, etc.

1 Like

as I wrote here:

it works only in that case.

I also just realized that the variable is the same in 2 screens since I cloned them, so I thought that that was interfering with the functionality, so I created 2 different variables for 2 different screens but it seems that it still makes the bug, where as ‘the bug’ I refer to the fact that the variable is NOT initialized to the value I set in the initialization block even after a companion app restart.

I’ll see if in a simple project the bug is present or not to understand if it’s my app’s problem.

that’s the way it’s supposed to work. the initialize-block only creates the variable - but optionally you can set it to a value or null or empty. but the variable retains its value only that time.
after looking at all the numerous examples in this forum, everyone seems to initialize without a value THEN load the intial value inside screen opens or screen starts. or before a do-block or if-block where it may get referenced like setting a list to empty before appending to it inside a do-block. it makes good programming practice most of the time - you can visually see nearby where the variable is intialized instead of looking all over the place for the corresponding initialize block.

1 Like

Ok, in complex projects that’s good practice, but I feel that if I inizialize a value to a variable it should have that value if I don’t touch it, unless the initialize feature is only meant to give the variable the property of number, string, boolean, etc, which is probably what happens with boolean, but I think it should be clarified otherwise people like me could think that it initializes the value.

I lost some time cause of this, if I knew I’d not lose it.
Maybe it’s my fault for not knowing something clear or maybe it IS already written somewhere and I didn’t read it. just saying.

I still don’t understand the bug you’re referring to.

If you initialize a variable, it will have the value you initialized it with. You can check that with a simple Label block inside of a When Screen Opens block. Are you saying that an initialized variable doesn’t show the value when you do exactly that? Because otherwise, it’s an issue with your logic, not the variable initialization procedure.

So, React native (the background language of thunkable) will let us create a variable without assigning it a type. this means, it waits to be assigned a value and will return null if you call it before a value is assigned.

app type can be set on initialization

stored type must be set programatically with blocks.

for an app i use these ‘stored’ type in, i want them available from day 1, so i create a splash screen that checks if ‘values set’ equals null or 1.
if it equals null, i set all stored variables to some initial value.
if it equals 1, then all my stored variables have some desired value in them and i can use them as needed.

you can get past this by using local storage instead of stored variables, but these require more blocks/code and you will be more prone to produce errors.

Sorry but I’m pretty sure that I was clear enough and I already explained what you ask.