Discuss Scratch

Scratch7696
Scratcher
59 posts

What does the ‘Lists’ do?

I don’t know anything about ‘Lists’, but I am just curious what does that do. Can someone tell me?
mstone326
Scratcher
1000+ posts

What does the ‘Lists’ do?

Just like a list in real life. Like going food shopping you can write out a list of items you would purchase, each with a number.
1. milk
2. eggs
3. candy!!

Then as you collect each item you could cross it off or delete it. You can realize you forgot something you can add it to the list. So we could add:
4. more candy!!!

Maybe your realize that more candy is the most important so we could insert it at the top of the list (or anywhere we want):
1. more candy!!!
2. milk
3. eggs
4. candy

That is the basic starting point. A variable holds 1 piece of data where a list can hold multiple of the same type.
TheTrillion
Scratcher
500+ posts

What does the ‘Lists’ do?

Scratch7696 wrote:

I don’t know anything about ‘Lists’, but I am just curious what does that do. Can someone tell me?
A list is kind of like a list in real life. It stores multiple pieces of information all at once. It does not reset itself unless if you put the ‘delete all’ block in the script. It can be used for inventories, or a record of the users answers for a question or more!

Last edited by TheTrillion (Feb. 9, 2021 22:49:00)

Scratchperson1000000
Scratcher
500+ posts

What does the ‘Lists’ do?

Just like a list in real life!
when green flag clicked
add [milk] to [groceries list v]
add [eggs] to [groceries list v]
add [frosting] to [groceries list v]
add [vegan] to [groceries list v]
if <(list) = [empty]> then
add [nothing] to [groceries list v]
Nezon
Scratcher
1000+ posts

What does the ‘Lists’ do?

The basic things are just to contain data in a list.

However, list really are used for advanced purposes, from giant sorting systems to systems that search 200000 files per second
Scratch7696
Scratcher
59 posts

What does the ‘Lists’ do?

Nice! But at what conditions can I use it for my project?
deck26
Scratcher
1000+ posts

What does the ‘Lists’ do?

Scratch7696 wrote:

Nice! But at what conditions can I use it for my project?
Imagine a list of values 1 to 52. Now randomly swap pairs of items and you have a shuffled deck of cards.

Imagine a list of questions and another of corresponding answers. You can now loop through them in few blocks of code to have a quiz rather than having every question and answer hard coded in blocks.

Imagine an inventory of items a player has collected in a game.

Imagine a snake game where clones of the snake's body use a list of previous positions of the snake's head to position themselves.

You get the idea. You don't always want to deal with data using individual variables for each value as that involves much more code. Loops and lists save a huge amount of work.
-EmeraldThunder-
Scratcher
1000+ posts

What does the ‘Lists’ do?

This is an example.

They store data. I built this script, taking advantage of lists to render very large amounts of tiles without a variable for each.
Scratch7696
Scratcher
59 posts

What does the ‘Lists’ do?

Many people wrote:

Lists store things inside.
So Lists store things inside? Can it store variables?
deck26
Scratcher
1000+ posts

What does the ‘Lists’ do?

Scratch7696 wrote:

Many people wrote:

Lists store things inside.
So Lists store things inside? Can it store variables?
It can store a copy of the value of a variable - it doesn't store the variable itself. That would be like a variable storing a variable.

Think of a list as a set of variables which can be referred to just by changing the index value.

So rather than representing a chess board using variables square1, square2, square3 and so on you'd have a list containing 64 items. So you might still want a variable for the position of the white king for example but the list for the board would include codes for blank squares and for each type of piece so when you're calculating possible moves you can see which squares are free, which are occupied by opponent's peices etc.

If you're struggling to understand this perhaps just wait until you have a project where you think it might be useful and ask again if you're still unsure.
yothisaccountisatest
New Scratcher
4 posts

What does the ‘Lists’ do?

Lists are pretty handy. I’ve made a project with Scratch lab where a random item selected from a new list will give you a writing suggestion.
Scratch7696
Scratcher
59 posts

What does the ‘Lists’ do?

deck26 wrote:

Scratch7696 wrote:

Many people wrote:

Lists store things inside.
So Lists store things inside? Can it store variables?
It can store a copy of the value of a variable - it doesn't store the variable itself. That would be like a variable storing a variable.

Think of a list as a set of variables which can be referred to just by changing the index value.

So rather than representing a chess board using variables square1, square2, square3 and so on you'd have a list containing 64 items. So you might still want a variable for the position of the white king for example but the list for the board would include codes for blank squares and for each type of piece so when you're calculating possible moves you can see which squares are free, which are occupied by opponent's peices etc.

If you're struggling to understand this perhaps just wait until you have a project where you think it might be useful and ask again if you're still unsure.
Nice, so Lists store units and save/carry them all the way to the end of the project, right?

Last edited by Scratch7696 (Feb. 10, 2021 22:39:59)

deck26
Scratcher
1000+ posts

What does the ‘Lists’ do?

Scratch7696 wrote:

deck26 wrote:

Scratch7696 wrote:

Many people wrote:

Lists store things inside.
So Lists store things inside? Can it store variables?
It can store a copy of the value of a variable - it doesn't store the variable itself. That would be like a variable storing a variable.

Think of a list as a set of variables which can be referred to just by changing the index value.

So rather than representing a chess board using variables square1, square2, square3 and so on you'd have a list containing 64 items. So you might still want a variable for the position of the white king for example but the list for the board would include codes for blank squares and for each type of piece so when you're calculating possible moves you can see which squares are free, which are occupied by opponent's peices etc.

If you're struggling to understand this perhaps just wait until you have a project where you think it might be useful and ask again if you're still unsure.
Nice, so Lists store units and save/carry them all the way to the end of the project, right?
Like variables, they store what you tell them to until you change them. But in the case of lists you an also delete items.
mitdk
Scratcher
1000+ posts

What does the ‘Lists’ do?

deck26 wrote:

Scratch7696 wrote:

deck26 wrote:

Scratch7696 wrote:

Many people wrote:

Lists store things inside.
So Lists store things inside? Can it store variables?
It can store a copy of the value of a variable - it doesn't store the variable itself. That would be like a variable storing a variable.

Think of a list as a set of variables which can be referred to just by changing the index value.

So rather than representing a chess board using variables square1, square2, square3 and so on you'd have a list containing 64 items. So you might still want a variable for the position of the white king for example but the list for the board would include codes for blank squares and for each type of piece so when you're calculating possible moves you can see which squares are free, which are occupied by opponent's peices etc.

If you're struggling to understand this perhaps just wait until you have a project where you think it might be useful and ask again if you're still unsure.
Nice, so Lists store units and save/carry them all the way to the end of the project, right?
Like variables, they store what you tell them to until you change them. But in the case of lists you an also delete items.
and store multiple things in one list, rather than just one thing. you can even make games through them! They're my favorite projects to make.
Joshia_T
Scratcher
500+ posts

What does the ‘Lists’ do?

On technical terms, I think you might be misunderstanding scratch “lists” and programming languages “lists”. While on other programming languages you can store variables in lists, scratch only stores “strings” into lists.

Non-technically, you can see the wiki here, for example if you want to remember the player's health every second you can store it into variables like “set health0 to health” on second 0, “set health1 to health” on second 1 but then you will be limited by how many variables you make, this is why sometimes you store things into a list. It's more of a convenient feature you can use, you don't have to use it since you can use variables instead but it will really help save time when you are familiar with it.

Basically lists contains values, these values act like variables. You can replace all variables with lists but variables are better to name. You can think of each values as a new variable that you can access with a number instead of name (the cool thing is that you can create or delete items, while you can't create or delete variables on scratch with blocks).
(var a)
(item (1 v) of [vars v] :: list) // acts the same as var a
(var b)
(item (2 v) of [vars v] :: list)
set [var a v] to [1]
replace item (1 v) of [vars v] with [1] // acts as the same as set var a to 1
Scratch7696
Scratcher
59 posts

What does the ‘Lists’ do?

Joshia_T wrote:

On technical terms, I think you might be misunderstanding scratch “lists” and programming languages “lists”. While on other programming languages you can store variables in lists, scratch only stores “strings” into lists.

Non-technically, you can see the wiki here, for example if you want to remember the player's health every second you can store it into variables like “set health0 to health” on second 0, “set health1 to health” on second 1 but then you will be limited by how many variables you make, this is why sometimes you store things into a list. It's more of a convenient feature you can use, you don't have to use it since you can use variables instead but it will really help save time when you are familiar with it.

Basically lists contains values, these values act like variables. You can replace all variables with lists but variables are better to name. You can think of each values as a new variable that you can access with a number instead of name (the cool thing is that you can create or delete items, while you can't create or delete variables on scratch with blocks).
(var a)
(item (1 v) of [vars v] :: list) // acts the same as var a
(var b)
(item (2 v) of [vars v] :: list)
set [var a v] to [1]
replace item (1 v) of [vars v] with [1] // acts as the same as set var a to 1
Sorry, I really can’t understand, can you simplify it? I am still at learning age
deck26
Scratcher
1000+ posts

What does the ‘Lists’ do?

Scratch7696 wrote:

Joshia_T wrote:

On technical terms, I think you might be misunderstanding scratch “lists” and programming languages “lists”. While on other programming languages you can store variables in lists, scratch only stores “strings” into lists.

Non-technically, you can see the wiki here, for example if you want to remember the player's health every second you can store it into variables like “set health0 to health” on second 0, “set health1 to health” on second 1 but then you will be limited by how many variables you make, this is why sometimes you store things into a list. It's more of a convenient feature you can use, you don't have to use it since you can use variables instead but it will really help save time when you are familiar with it.

Basically lists contains values, these values act like variables. You can replace all variables with lists but variables are better to name. You can think of each values as a new variable that you can access with a number instead of name (the cool thing is that you can create or delete items, while you can't create or delete variables on scratch with blocks).
(var a)
(item (1 v) of [vars v] :: list) // acts the same as var a
(var b)
(item (2 v) of [vars v] :: list)
set [var a v] to [1]
replace item (1 v) of [vars v] with [1] // acts as the same as set var a to 1
Sorry, I really can’t understand, can you simplify it? I am still at learning age
There are times when a list is far more sensible than multiple variables - I'd say it's misleading to say otherwise.

I'll repeat my earlier comment, why not wait until you think you need them when your experience of Scratch amy have increased.

Alternatively deliberately go for a project where lists make sense. How about a simple project to store a deck of playing cards as numbers 1 to 52 which should then be shuffled and deal a hand of 7 cards which you can show using stamping. My project here https://scratch.mit.edu/projects/2866621/ will save you a lot of preparatory work.
Scratch7696
Scratcher
59 posts

What does the ‘Lists’ do?

deck26 wrote:

Scratch7696 wrote:

Joshia_T wrote:

On technical terms, I think you might be misunderstanding scratch “lists” and programming languages “lists”. While on other programming languages you can store variables in lists, scratch only stores “strings” into lists.

Non-technically, you can see the wiki here, for example if you want to remember the player's health every second you can store it into variables like “set health0 to health” on second 0, “set health1 to health” on second 1 but then you will be limited by how many variables you make, this is why sometimes you store things into a list. It's more of a convenient feature you can use, you don't have to use it since you can use variables instead but it will really help save time when you are familiar with it.

Basically lists contains values, these values act like variables. You can replace all variables with lists but variables are better to name. You can think of each values as a new variable that you can access with a number instead of name (the cool thing is that you can create or delete items, while you can't create or delete variables on scratch with blocks).
(var a)
(item (1 v) of [vars v] :: list) // acts the same as var a
(var b)
(item (2 v) of [vars v] :: list)
set [var a v] to [1]
replace item (1 v) of [vars v] with [1] // acts as the same as set var a to 1
Sorry, I really can’t understand, can you simplify it? I am still at learning age
There are times when a list is far more sensible than multiple variables - I'd say it's misleading to say otherwise.

I'll repeat my earlier comment, why not wait until you think you need them when your experience of Scratch amy have increased.

Alternatively deliberately go for a project where lists make sense. How about a simple project to store a deck of playing cards as numbers 1 to 52 which should then be shuffled and deal a hand of 7 cards which you can show using stamping. My project here https://scratch.mit.edu/projects/2866621/ will save you a lot of preparatory work.
Ok

Powered by DjangoBB