Discuss Scratch
- Discussion Forums
- » Suggestions
- » Dictionaries AND Lists [A lot of supporters]
- A-MARIO-PLAYER
-
1000+ posts
Dictionaries AND Lists [A lot of supporters]
This is technically 2D lists, which is rejected.
- PaperMarioFan2022
-
1000+ posts
Dictionaries AND Lists [A lot of supporters]
Something like this? This is technically 2D lists, which is rejected.
1.6 2D listsI don't believe it is the same thing. It looks completely different.
2D lists, also known as 2D arrays, nested lists, or matrices, are a type of data structure that allows you to put an entire list as an element of another list; that is, it allows you to put lists inside of lists. These sorts of data structures are used widely in other programming languages and functions similarly to a table.
This block, and others, would allow you to create 2D lists to store information. However, this is too complicated for what is supposed to be an introductory programming language. There are workarounds possible by using an ordinary list and an indexing function. For those who are interested, it may be worth checking out Snap!. It is a block-based programming language designed for experienced programmers and has more advanced data structures than Scratch does.
- WindowsAdmin
-
1000+ posts
Dictionaries AND Lists [A lot of supporters]
This is a 2014 topic, it would have been closed by now This is technically 2D lists, which is rejected.
- Honey_Dreamz
-
100+ posts
Dictionaries AND Lists [A lot of supporters]
There is a workaround; add the items to a list in such a way that makes sure they have the same number. For example, item number one in list1 corresponds to item number 1 in list2, etcetera. Then, you can use these corresponding list numbers to do whatever you would need to do with dictionaries. Although the dictionaries make it a bit simpler, the workaround truly isn't that difficult either in my opinion, just needs a few extra blocks to make it work.
Last edited by Honey_Dreamz (Oct. 4, 2024 10:06:36)
- 8to16
-
1000+ posts
Dictionaries AND Lists [A lot of supporters]
Support only if it's an extension. It would be pretty useful for some projects I am planning, but this will confuse many new scratchers — however, probably not as many as sin or cos already does.
Last edited by 8to16 (Jan. 6, 2025 17:28:21)
- Cool_kid092
-
500+ posts
Dictionaries AND Lists [A lot of supporters]
semi support. tho it would be cool for something else, it would be confusing for new scratchers
- jmb1293634
-
1000+ posts
Dictionaries AND Lists [A lot of supporters]
this is rejected: I think that we should just have lists within lists, so 2d, 3d, even 4d lists.
Then we could do:(item (1 v) of (item (2 v) of [list v]))
1.6 2D lists
2D lists, also known as 2D arrays, nested lists, or matrices, are a type of data structure that allows you to put an entire list as an element of another list; that is, it allows you to put lists inside of lists. These sorts of data structures are used widely in other programming languages and functions similarly to a table.
This block, and others, would allow you to create 2D lists to store information. However, this is too complicated for what is supposed to be an introductory programming language. There are workarounds possible by using an ordinary list and an indexing function. For those who are interested, it may be worth checking out Snap!. It is a block-based programming language designed for experienced programmers and has more advanced data structures than Scratch does.add () to sublist () of [list v]::lists stack
Last edited by jmb1293634 (Jan. 6, 2025 17:50:06)
- tagrim123
-
500+ posts
Dictionaries AND Lists [A lot of supporters]
Bump because i unknowingly made a dupe.
- bubgamer07
-
100+ posts
Dictionaries AND Lists [A lot of supporters]
((Support!::operators)::grey)very useful
- khattabn
-
11 posts
Dictionaries AND Lists [A lot of supporters]
How to do this :
Create two lists, one for the items and one for the values, and for example : one named “ItemNames” and another named “ItemValues”.
Also, make two variables one named “found?” and another named “Index”
First, this is how to add things to your inventory, make a block named add item (Name) amount : (Amount) and define it like this:
You collected a gold coin what will happen? Well, easily :
But what about removing items? Well you must make another costume block : Remove item (item) amount : (Amount)
Cool right? But we need one more thing.. how to read the value of an item. Which isn't that hard. For example, this reads how many wood the player has :
You bought some wood? easily :
See? Simple right? So you have three choices if you want to make an inventory :
1. Make separate variables : Messy, complex, unreadable and hard to update
2. Make one list : Easy to update but can't store values
3. Use this way : Neat, clean, readable, easy to update and can store values
Create two lists, one for the items and one for the values, and for example : one named “ItemNames” and another named “ItemValues”.
Also, make two variables one named “found?” and another named “Index”
First, this is how to add things to your inventory, make a block named add item (Name) amount : (Amount) and define it like this:
define add item (item) amount : (Amount)
set [found? v] to [0]
set [index v] to [1]
repeat (length of [ItemNames v] :: list)
if <(item) = (item (index) of [ItemNames v] :: list)> then
replace item (index) of [ItemValues v] with ((item (index) of [ItemValues v] :: list) + (Amount))
set [found? v] to [1]
end
change [index v] by (1)
end
if <(found?) = [0]> then
add (item) to [ItemNames v]
add (Amount) to [ItemValues v]
end
You collected a gold coin what will happen? Well, easily :
add item [Gold] amount : (1)
But what about removing items? Well you must make another costume block : Remove item (item) amount : (Amount)
define Remove item (item) amount : (Amount)
set [index v] to [1]
repeat (length of [ItemNames v] :: list)
if <(item) = (item (index) of [ItemNames v] :: list)> then
replace item (index) of [ItemValues v] with ((item (index) of [ItemValues v] :: list) - (Amount))
if <(item (index) of [ItemValues v] :: list) < [1]> then
delete (index) of [ItemNames v]
delete (index) of [ItemValues v]
end
end
change [index v] by (1)
end
Cool right? But we need one more thing.. how to read the value of an item. Which isn't that hard. For example, this reads how many wood the player has :
(item (item # of [Wood] in [ItemNames v]) of [ItemValues v] :: list)
You bought some wood? easily :
if <(item (item # of [Coins] in [ItemNames v]) of [ItemValues v] :: list) > [2]> then
Remove item [Coins] amount : (3)
add item [wood] amount : (3)
end
See? Simple right? So you have three choices if you want to make an inventory :
1. Make separate variables : Messy, complex, unreadable and hard to update
2. Make one list : Easy to update but can't store values
3. Use this way : Neat, clean, readable, easy to update and can store values
Last edited by khattabn (June 20, 2025 20:26:46)
- tagrim123
-
500+ posts
Dictionaries AND Lists [A lot of supporters]
medians carrying this topic. Bringing this topic up.
- Discussion Forums
- » Suggestions
-
» Dictionaries AND Lists [A lot of supporters]