I am adding this post under Video Tutorials since the discussion stems from a video tutorial I made on how to create a simple to do / task management app. Here is the original video:
Someone tried replicating the app and wanted to enhance it by storing the tasks in a stored / local variable. However, this code was not working.
Here are the original blocks.
The problem was he was trying to add the input item to a list variable BUT the variable had not been initialized (or defined) as a list.
An Incorrect Solution
Your 1st instinct may be to set the variable to an empty list whenever the screen starts. This does not work because the app ends up clearing out the list every time you close and reopen the app. This defeats the purpose of the stored variable.
The Correct Solution
Rather, a better approach is to only set the variable to an empty list IF the list has not yet been defined. This makes the stored variable a list variable IF and ONLY IF the list is not yet defined. Thus it will not clear out any items previously stored in the list.
The Final Code
These are the final blocks that I got to work.
Let me know if you have a better solution to this - hope this helps you in your troubleshooting in the future!
Thunkable X Tutorials