Here is something that might help:
Variables start with their value being zero:
However for the common list blocks you need the variable to be a list: you can't
add anything to a list that doesn't exist. It is important to understand that while Snap! isn't a strongly typed language, zero is not in any way shape or form a list. So, if you try to add something to your variable, you will get an error:
![untitled script pic (13)](https://cdn.forum.snap.berkeley.edu/original/3X/a/e/ae90047e726040ce65e9096b086a179d4d32e7f8.png)
So, to fix this, we need to make sure that the variable is a list
first. To do this, we can set the variable to an empty list:
Now, when we try a list operation on the variable (e.g. adding to the list), it works!
There is another reason why you will want to initialize your variable as an empty list:
Let's say someone runs your project, and the variable "a" becomes a list of 10 items:
Then, the next time they run your project, your list will
still have those ten items. So, if they do the same names again, your list will look like this:
So that is yet another reason why you want to set your variable to an empty list at the start of your project.
For getting user input, you could use the "ask" block (already mentioned in this thread):
![untitled script pic (18)](https://cdn.forum.snap.berkeley.edu/original/3X/4/e/4ee6ba1537bc1343734d5f59419cc76bebafae40.png)
To determine whether to display an error or add to a list, an if-else block is in order:
For your error, you could do something like this:
Basically, your result should be visible. You could either use
![untitled script pic (21)](https://cdn.forum.snap.berkeley.edu/original/3X/b/1/b1352678a424be4559abc5cca1d5a970aa5ea82a.png)
which will show the variable's value on the stage, or you could do:
![untitled script pic (22)](https://cdn.forum.snap.berkeley.edu/original/3X/9/a/9a34ecc607298dc13c3201bbeb29587e46b8a810.png)
Which will have a similar result, only in a speech bubble.
I hope this helps!
PS: You don't need to use the block script variables ((a)) @> to create your variable - instead use the
button. I just used it for simplicity to create the pictures.
PPS: The difference between these methods for creating variables is that the block creates a variable only available to the script that it was created in and this variable is not saved with the project.
(I know that you are already confused with some things in Snap, so only look at this [by clicking on the blurred text] if you're sure that it won't make you even more confused. Maybe just forget that the script variables block exists for now.)