Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Pls explain lists to me
- squelz
-
Scratcher
35 posts
Pls explain lists to me
im just working on a project for free time and idk how to use lists
- 96498cb
-
Scratcher
100+ posts
Pls explain lists to me
uh so basically they are a list of things that you can use for like inventory and custom x & y games
- EpicGhoul993
-
Scratcher
1000+ posts
Pls explain lists to me
For basic information, I recommend reading the Scratch Wiki. Here is the article about lists.
- deck26
-
Scratcher
1000+ posts
Pls explain lists to me
Imagine you wanted to draw a shape but didn't know how many sides it had but wanted it to have up to 8 sides. You don't want to have to store 8 x-values and 8 y-values all in different variables as that would be hard to keep track of. Even harder if you wanted to ba able to remove one vertex and replace it with a new one in a different position so, for example, the fourth point is now the third, the fifth is the fourth and the new point is the new fifth point.
With a list of x values you can store as many x values as you want. A corresponding list would store the y-values. Now if the third pont is removed you just remove the third items from both lists. The lists now contain one item fewer and you can insert a new value at the fifth position in each list to replace it (if required).
You can then draw the shape by using a loop
go to item 1 of x-list, item 1 of y-list
pen down
set var1 to 2
repeat until var1 > length of x-list
go to item var1 of x-list, item var1 of y-list
change item1 by 1
end repeat loop
go to item 1 of x-list, item 1 of y-list
pen up
That simple loop will draw a triangle or a square or a pentagon or whatever - it just depends how long the list is.
That's just one example but shows how useful a list can be to handle multiple values.
With a list of x values you can store as many x values as you want. A corresponding list would store the y-values. Now if the third pont is removed you just remove the third items from both lists. The lists now contain one item fewer and you can insert a new value at the fifth position in each list to replace it (if required).
You can then draw the shape by using a loop
go to item 1 of x-list, item 1 of y-list
pen down
set var1 to 2
repeat until var1 > length of x-list
go to item var1 of x-list, item var1 of y-list
change item1 by 1
end repeat loop
go to item 1 of x-list, item 1 of y-list
pen up
That simple loop will draw a triangle or a square or a pentagon or whatever - it just depends how long the list is.
That's just one example but shows how useful a list can be to handle multiple values.
Last edited by deck26 (Feb. 11, 2025 15:52:37)
- squelz
-
Scratcher
35 posts
Pls explain lists to me
so what can lists be used for in making a game? and is it possible to have a projectile go to a clone of another sprite
Last edited by squelz (Feb. 11, 2025 19:17:06)
- GameCatastrophe0927
-
Scratcher
1000+ posts
Pls explain lists to me
so what can lists be used for in making a game? and is it possible to have a projectile go to a clone of another spriteLists can be used for saving large amounts of data, turning multiple numbers into one larger number, scanning strings letter-by-letter, storing prices, and a lot of stuff like that.
- souleymane2
-
Scratcher
100+ posts
Pls explain lists to me
is it possible to have a projectile go to a clone of another sprite
if you save every position of the clones in a list you can indeed achieve this.
Assign every clone an ID value (as a number) and create two list.
Every clone will then edit its id value to its current position like so:
replace item (clone#) of [clone x v] with (x position)
replace item (clone#) of [clone y v] with (y position)
Then to have a projectile move to the 4th clone for example you just have to move it to the 4th positions like so:
glide (1) secs to x: (item # of [4] in [clone x v]) y: (item # of [4] in [clone y v])
- kyoufu_gaaden
-
Scratcher
85 posts
Pls explain lists to me
If you know what variables are, they are basically capable storing several variables at once. They are like banks of info.
- deck26
-
Scratcher
1000+ posts
Pls explain lists to me
can i get an example of this being used in a gameAny particular use of lists or just any?
https://scratch.mit.edu/projects/46472058/ uses lists for the x and y positions of the clones.
- Discussion Forums
- » Help with Scripts
-
» Pls explain lists to me






