Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to tell if a list item is empty
- ohforfs
-
New Scratcher
6 posts
How to tell if a list item is empty
Hi,
I can find no way of checking if an individual item on a list is empty. I can check if it is > 0, but that's not the same thing.
Can someone tell me how to do it please?
Thanks
I can find no way of checking if an individual item on a list is empty. I can check if it is > 0, but that's not the same thing.
Can someone tell me how to do it please?
Thanks

- ohforfs
-
New Scratcher
6 posts
How to tell if a list item is empty
EDIT: I am NOT wanting to find out if the whole list is empty, I can do that. It's for the individual items in a list that I wish to check.
- weegaweek
-
Scratcher
100+ posts
How to tell if a list item is empty
by empty, do you mean an empty string, or do you mean that the item does not exist?
for the former, use this:
for the latter, use this:
for the former, use this:
<(item (index) of [list v] :: list) = []>
for the latter, use this:
<not <((length of [list v] :: list) + (1)) > (index)>>
Last edited by weegaweek (Jan. 19, 2020 18:20:37)
- ohforfs
-
New Scratcher
6 posts
How to tell if a list item is empty
by empty, do you mean an empty string, or do you mean that the item does not exist?
for the former, use this:<(item (index) of [list v] :: list) = []>
for the latter, use this:<not <((length of [list v] :: list) + (1)) > (index)>>
It's ONE item in the list I am checking. So my pigeonhole sort creates a tempory list that contains (almost always) blank items in the list. So item 3 might be blank and unset at the end of the first part of the process. I need to know when a slot is blank but there seems no comparison that can check individual list items are empty. Thanks for your help, I appreciate it.
- ohforfs
-
New Scratcher
6 posts
How to tell if a list item is empty
EDIT: I am NOT wanting to find out if the whole list is empty, I can do that. It's for the individual items in a list that I wish to check.
by empty, do you mean an empty string, or do you mean that the item does not exist?
for the former, use this:<(item (index) of [list v] :: list) = []>
for the latter, use this:<not <((length of [list v] :: list) + (1)) > (index)>>
It's ONE item in the list I am checking. So my pigeonhole sort creates a tempory list that contains (almost always) blank items in the list. So item 3 might be blank and unset at the end of the first part of the process. I need to know when a slot is blank but there seems no comparison that can check individual list items are empty. Thanks for your help, I appreciate it.
- weegaweek
-
Scratcher
100+ posts
How to tell if a list item is empty
It's ONE item in the list I am checking. So my pigeonhole sort creates a tempory list that contains (almost always) blank items in the list. So item 3 might be blank and unset at the end of the first part of the process. I need to know when a slot is blank but there seems no comparison that can check individual list items are empty. Thanks for your help, I appreciate it.when you add an item to a list, you give it a value. no item in a list is truely “empty”. but you can use a special string (“*empty*”, for example) whenever you add an item to a list in your code, and then check whether the item has been set to somthing else by checking if its value is still equal to that string. if you need to locate all of the empty items, you can loop through the list to search for them.
EDIT: I am NOT wanting to find out if the whole list is empty, I can do that. It's for the individual items in a list that I wish to check.you can click “edit” on the bottom of your posts, you dont need to quote yourself.
- ohforfs
-
New Scratcher
6 posts
How to tell if a list item is empty
The items that are left blank on the list are simply not there after initialisation. Like a list of 10 items but only 8 are filled. This happens due to you being able to create lists from the variable menu and would also happen in real life. So I have the same question if you please, how do I know an item on the list is “empty” - not the whole list, an item on the list.
- weegaweek
-
Scratcher
100+ posts
How to tell if a list item is empty
The items that are left blank on the list are simply not there after initialisation. Like a list of 10 items but only 8 are filled. This happens due to you being able to create lists from the variable menu and would also happen in real life. So I have the same question if you please, how do I know an item on the list is “empty” - not the whole list, an item on the list.no item is empty. they appear empty because they contain the empty string, “”. the first script I showed will report whether or not an item contains the empty string:
<(item (the index of the item that you want to check :: grey) of [list v] :: list) = []>//this box does not contain a space
there is no block that does this for you because it would be unnecesary:
<is item () of [list v] empty? :: list>
- deck26
-
Scratcher
1000+ posts
How to tell if a list item is empty
<(length of (item (n v) of [list v] :: list)) = [0]>
- ohforfs
-
New Scratcher
6 posts
How to tell if a list item is empty
<(length of (item (n v) of [list v] :: list)) = [0]>
Thank you - that is exactly it.
- SoggynoodlesTNT
-
Scratcher
46 posts
How to tell if a list item is empty
Maybe something like this?
if <(item (number v) of [list v] :: list) = []> then
code here
end
- Wizard3245
-
Scratcher
15 posts
How to tell if a list item is empty
My browser / operating system: ChromeOS 14541.0.0, Chrome 151.0.0.0, No Flash version detected
move (66876) steps
- ITS_DINO_XD
-
Scratcher
100+ posts
How to tell if a list item is empty
My browser / operating system: ChromeOS 14541.0.0, Chrome 151.0.0.0, No Flash version detectedthis post has nothing to do with the topic please don't share nonsensical postsmove (66876) steps
- Discussion Forums
- » Help with Scripts
-
» How to tell if a list item is empty