# Variable not saving properly

**URL:** <https://community.thunkable.com/t/variable-not-saving-properly/50992>\
**Category:** Questions about Thunkable X\
**Created:** [October 8, 2018, 9:52pm UTC](https://community.thunkable.com/t/variable-not-saving-properly/50992 "2018-10-08T21:52:11Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![AcrobatEpee](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/acrobatepee/32/26336_2.png) [@AcrobatEpee](https://community.thunkable.com/u/AcrobatEpee)\
**Post date:** [October 8, 2018, 9:52pm UTC](https://community.thunkable.com/t/variable-not-saving-properly/50992/1 "2018-10-08T21:52:11Z")

</div>

Hey !

So let me explain :

I have these blocks

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

Which leads to the execution of these blocks

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/7/87a398175aad5483113faed7c150abf8db1a2964.png)

And these are working fine. But, when I try to use the same variable in another procedure that has no links with these (Launches when a button is clicked), it doesn’t work…Here are the blocks :

The button ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/4/54c4855ae2a4ffd79a4ec315f4b85d692cb28fe5.png) executing ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/a/2a31a8384f06494fe771953ab827b753c69b715c.png)

The `index` variable is not working here, the `name` one is working fine strangely

Any ideas on what is going wrong ? Thank you !

---

<div class="post-metadata">

**Author:** ![AcrobatEpee](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/acrobatepee/32/26336_2.png) [@AcrobatEpee](https://community.thunkable.com/u/AcrobatEpee)\
**Post date:** [October 9, 2018, 4:45pm UTC](https://community.thunkable.com/t/variable-not-saving-properly/50992/2 "2018-10-09T16:45:42Z")

</div>

Anyone ? This is really disturbing, it never happened to me

Here a picture describing better : The ones in red are the ones in which the variables are showing undefined and the ones in green where the variables work fine :

 ![Sans%20titre-1](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/9/b900595c85d390fedfe3fb9b2bf97b74849083f2.png)

Hey @Mark ! Any idea on that one ? Maybe it’s a bug when you get out of the function the variable returns to nothing or I don’t know 😕

Thanks !

---

<div class="post-metadata">

**Author:** ![paulmw](https://avatars.discourse-cdn.com/v4/letter/p/22d042/32.png) [@paulmw](https://community.thunkable.com/u/paulmw)\
**Post date:** [October 9, 2018, 8:44pm UTC](https://community.thunkable.com/t/variable-not-saving-properly/50992/3 "2018-10-09T20:44:05Z")

</div>

You can’t modify the list viewer’s text items directly using the list remove block.

What you need to is create a variable, set the list to that variable, modify the list, and then set the list items to be what’s in the list.

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

Example project  
[https://x.thunkable.com/copy/8048f4b3458eb997d994678d924bbfb7](https://x.thunkable.com/copy/8048f4b3458eb997d994678d924bbfb7)

---

<div class="post-metadata">

**Author:** ![AcrobatEpee](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/acrobatepee/32/26336_2.png) [@AcrobatEpee](https://community.thunkable.com/u/AcrobatEpee)\
**Post date:** [October 9, 2018, 8:53pm UTC](https://community.thunkable.com/t/variable-not-saving-properly/50992/4 "2018-10-09T20:53:30Z")

</div>

Thanks for the trick but the problem is still that the variables aren’t saving the values out of the green blocks 😕

Also I didn’t understand what you were referring to. Are you saying that I can’t remove an item from the list by directly inserting the listviewer into the in list … block ? Because it works perfectly for me 🙂

---

<div class="post-metadata">

**Author:** ![paulmw](https://avatars.discourse-cdn.com/v4/letter/p/22d042/32.png) [@paulmw](https://community.thunkable.com/u/paulmw)\
**Post date:** [October 9, 2018, 9:52pm UTC](https://community.thunkable.com/t/variable-not-saving-properly/50992/5 "2018-10-09T21:52:51Z")

</div>

Oh, you are correct - you can use the green blocks that way…that’s scary but true.

To the first question, the problem is that you are naming the variable “index” when the green block is already called index. These values clash with each other, meaning you can’t update the global variable “index” inside the ItemClick event.

Basically your orange variable blocks (index, name) and the green variable blocks (item, index, etc) should **NEVER** have the same names. Eventually we’ll change the system so this problem is more obvious.

---

<div class="post-metadata">

**Author:** ![Mark](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/mark/32/18133_2.png) [@Mark](https://community.thunkable.com/u/Mark)\
**Post date:** [October 9, 2018, 9:55pm UTC](https://community.thunkable.com/t/variable-not-saving-properly/50992/6 "2018-10-09T21:55:53Z")

</div>

The first thing that I would do is to have different names for the global variables that you use and the argument names for your procedures. Using the same name (e.g. `'index'`) is just asking for trouble. For example, in your `'check'` procedure you increment the value of `'index'`. Which version of `'index'` do you mean? The one that is local to the `'check'` procedure or the global `'index'` variable that is accessible to all your blocks? Changing those names might itself fix your problem, but if not it will make it much easier to diagnose what is going wrong.

-Mark

---

<div class="post-metadata">

**Author:** ![AcrobatEpee](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/acrobatepee/32/26336_2.png) [@AcrobatEpee](https://community.thunkable.com/u/AcrobatEpee)\
**Post date:** [October 9, 2018, 10:06pm UTC](https://community.thunkable.com/t/variable-not-saving-properly/50992/7 "2018-10-09T22:06:07Z")

</div>

Ok so basically if I open a procedure with whatever = index  
whatever1 = count

It doesn’t change anything ? Didn’t understand it this way 😕 Thanks !

---

<div class="post-metadata">

**Author:** ![Mark](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/mark/32/18133_2.png) [@Mark](https://community.thunkable.com/u/Mark)\
**Post date:** [October 9, 2018, 10:30pm UTC](https://community.thunkable.com/t/variable-not-saving-properly/50992/8 "2018-10-09T22:30:04Z")

</div>

> [@AcrobatEpee](#):
>
> Ok so basically if I open a procedure with whatever = index  
> whatever1 = count

I’m sorry, I don’t know what you mean by the above.

-Mark

---

<div class="post-metadata">

**Author:** ![AcrobatEpee](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/acrobatepee/32/26336_2.png) [@AcrobatEpee](https://community.thunkable.com/u/AcrobatEpee)\
**Post date:** [October 9, 2018, 10:31pm UTC](https://community.thunkable.com/t/variable-not-saving-properly/50992/9 "2018-10-09T22:31:58Z")

</div>

I’m saying that the way you name the arguments of the procedure is not linked to the name of your variables right ? I’m pretty stupid I didn’t get that in the first time 😕 I’m downloading the app at the moment, will keep you updated.

Thanks

---

<div class="post-metadata">

**Author:** ![AcrobatEpee](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/acrobatepee/32/26336_2.png) [@AcrobatEpee](https://community.thunkable.com/u/AcrobatEpee)\
**Post date:** [October 10, 2018, 11:27am UTC](https://community.thunkable.com/t/variable-not-saving-properly/50992/10 "2018-10-10T11:27:54Z")

</div>

Thanks @Mark and @paulmw, my issue is fixed, but two more are left.

This one on getting a list from localstorage : [Saving & Getting an information after the app was closed](http://community.thunkable.com/t/saving-getting-an-information-after-the-app-was-closed/51056)

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/2/225a875fa1676bda6b1c54b9dd25a4ddafd3b849.png)

And another one is about the next screenshot, these blocks are supposed to replace the item at the #position but it just doesn’t change it, it adds a new one 😕

Also, the edit variable only is set to 2 the first time the list is clicked, after that it never works.

Thanks for helping

[https://streamable.com/coe7i](https://streamable.com/coe7i)

---

<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:55am UTC](https://community.thunkable.com/t/variable-not-saving-properly/50992/11 "2024-11-08T11:55:12Z")

</div>


