Categories
BLOG

does scratch have lists

Does scratch have lists

The Scratch Wiki is made by and for Scratchers. Do you want to contribute?

A list (also called an array in other programming languages) is a tool that can be used to store multiple pieces of information at once. It can also be defined as a variable containing multiple other variables. A list consists of a numbers paired with items. Each item can be retrieved by its paired number. List blocks can be found in the Data blocks palette.

Contents

  • 1 List Blocks
  • 2 Items
  • 3 Limits on List Size
  • 4 Example Uses
    • 4.1 More Complex Uses
    • 4.2 Copy and Pasting
  • 5 Cloud Lists
  • 6 Casting
  • 7 List Editor
    • 7.1 Usage
    • 7.2 Limitations
  • 8 Example Projects
  • 9 Requests
  • 10 See Also
  • 11 References

List Blocks

The following blocks can be used to program lists:

  • add [thing] to [list v] — Adds an item to a list
  • delete (1) of [list v] — Deletes a chosen item of a list
  • insert [thing] at (1) of [list v] — Inserts an item at a chosen point in a list
  • replace item (1) of [list v] with [thing] — Replaces an item in a list with a new item
  • (list :: list) — A reporter block with few uses; however, this can be used as a Stage Monitor
  • (item (1) of [list v]) — A reporter block that reports what text an item in a list contains
  • item # of [thing] in [list v] — Reports the index in a list where an item first appears
  • (length of [list v]) — A reporter block that reports how many items a list contains
  • — A boolean block that checks if a list contains a given string.
  • show list [list v] — Shows the specified list’s stage monitor
  • hide list [list v] — Hides the specified list’s stage monitor

Items

Items can be added to or deleted from a list manually or by programming. Holding down shift and pressing enter on a list results in a new entry above the previously selected entry, and pressing enter without the shift key creates a list entry below the previously selected one. They can also be added by right-clicking the list, clicking ‘import’, and selecting a plain .txt or Comma Separated Values file. Each line in the file will become a new item in the list.
They can also be exported in the same way; however, it is not possible to do so if the list has a name which is unsupported in the user’s operating system. In Windows, lists using question marks (?), asterisks (*), angle brackets ( ), pipes (|), a colon (:), a space ( ), or any ASCII control character cannot be exported with Scratch. The first time the export button is pressed for this type of list, nothing will happen; following the second click, the import/export menu will close. [1] [2] The allowed characters will vary between operating systems.

Limits on List Size

In previous versions of the Scratch editor, there is no limit to the length of an item or the number of items a list can hold, apart from an amount sufficient to crash Scratch. However, in old versions of the online editor, a project may have been rendered unable to save online if a list took too long to upload, because Scratch returns a network error after about 30 seconds. This happened at around 300,000 list items.

In Scratch 3.0, lists have a hard size limit of 200,000 items. [3]

Example Uses

Some example uses for lists are as follows:

  • Calculations
  • Encoding/Decoding strings
  • Inventories
  • Artificial Intelligence
  • Recording multiple values
  • Conserving variables
  • Saving and loading data

More Complex Uses

  • Storing user-input data in Operating System simulations
  • Storing AI data in games
  • Allowing users to re-create past inputs

Copy and Pasting

Because text in lists can be copied and pasted into text documents, and the data in lists can also be exported or imported, lists can be used to create save systems (along with the Ask () and Wait block).

Cloud Lists

Cloud lists were an experimental feature in alpha and beta versions of Scratch 2.0. However, they were disabled when Scratch 2.0 was released. The values of cloud lists were stored on the Scratch servers; this was the only difference between them and regular lists. When a cloud list got updated, it did so across all copies of the project. This makes cloud lists ideal for things like public high score lists. Many users wanted cloud lists to come back because it would make coding easier for them. [4]

Casting

Lists are cast to numbers and strings with a set of explicit rules depending on its contents.

List Editor

The List Editor is a feature that allows you to edit lists. It is only avalible inside the project editor. Use it by clicking on a list item and typing in the new list item. You can also delete an item by clicking the “X” at the right and add an item by clicking the “+” at the bottom left of the list area.

Usage

The list editor can be used to make Programming languages in Scratch by importing a *.txt file into the list. It is also useful when a project needs users to edit a list. The list editor is not as widely used as many other features such as Say and Ask. Many Scratchers do not know about the list; therefore, not many projects use it. [ citation needed ]

The list editor is also useful in text editors as creating a full text editor in Scratch is almost impossible because of the limitations of what characters can be used in the Key () Pressed? block. Text editors using list editors are easy to code as the project just has to access the list item.

Limitations

The list editor has many limitations, which is why it is not widely used. It can only be used in the project editor, which means users can see all the code and edit it. Its use of Scratch features also means that it is hard on the user and is not customizable at all. List editors also do not have the best user interface, and it is often misleading for the user. Because of this, very few projects use the list editor and it is a very little-known feature.

Example Projects

  • Fibonacci Generator by makethebrainhappy
  • FruitcraftRPG by Wodunne
  • Random Level Generator by poopo
  • Scratch Memory by spaceguy12

Requests

From the time lists were introduced, many users requested two new blocks, hide list [list v] and show list [list v] . Due to such high demand, they were introduced in Scratch 2.0.

Some users have suggested adding two-dimensional, or even multidimensional, lists. [5] However, the Scratch Team has rejected that suggestion, stating that it would be too complicated for a programming language meant for beginners. [6]

Does scratch have lists The Scratch Wiki is made by and for Scratchers. Do you want to contribute? A list (also called an array in other programming languages) is a tool that can be used to

Curnow.biz

Phil Curnow’s Blog

Lists in Scratch 2

Variables in Scratch allow us to store a single piece of data that we can use in our scripts. This blog post will introduce Lists (also known as arrays in other programming languages). Where variables allow us to store a single piece of information, lists allow us to store multiple pieces of information in the same way we would make a list of items on a sheet of paper. One of the most common lists we make in our lives is a shopping list, and I will use the idea of a shopping list to explain the concept of Scratch lists.

When we write a list on paper, we very often add items to the list from top to bottom, i.e. we add item 1, then item 2, etc. We can do this with lists in Scratch, and we can also insert items at a specific location in the list, remove items from a list, etc. In this post we will cover all the actions you can perform on a list. Code blocks will also be given to show exactly how you express this in the Scratch environment.

Creating a List

To create a list in Scratch, from the Block palette select Data and then click the Make a List button, give your list a name and then click OK, an empty list is then displayed on the Stage. At this point you are then ready to start adding items to your list. In all the example code blocks in this post, the list will be called ShoppingList.

Adding Items

To add an item to our list, we use the add block, which looks like:

Where we see the word thing , we replace this with the word, number or sentence we want to add to the list. Looking at the picture of the list at the beginning of this post, we can see the first item in the list is Apples, so we replace thing with Apples, and we then have our first item in the list. If we then add another item, say Oranges, you will see that this is added to the bottom of the list. As we keep adding, the list grows. In programming terms, a list is dynamic in size, meaning it is not a fixed length.

As we are building a shopping list, we want to be able to add many items to it. The code block below allows this to happen. All the code is doing is repeating a block of code asking the user what they want to add to the list. If the user enters the word finish the code block stops.

Inserting Items

So, as we can see its very easy to add items to the end of a list. What about if we want to insert an item within our list? Well this is very easy to do by using the insert block. The insert block allows us to specify what we want to insert and the position in the list where we would like to insert it. If you click on the drop down on the insert block, you will see by default the options 1, last and random. Selecting 1 will insert the item at position 1 in the list, moving the current items in the list down by 1 position (so the current item 1 becomes item 2, etc), last will insert at the end of the list (the same as adding) and random will insert into a random position in the list. We are able to specify the exact position in the list we would like to insert our item. The code block below shows an example of inserting into a list.

We simply specify what we would like to insert into the list and the position we would like to insert to. So, using the example of our list at the beginning of this post, if we inserted Milk at position 3, our list would then look like:

1. Apples
2. Oranges
3. Milk
4. Grapes
5. Bread
6. Cheese

As you can see, everything that was in position 3 onwards in the list has now moved down one position.

Deleting from a List

Deleting, or removing items from a list is achieved by using the delete block. You specify the item number you want to delete from the list. By default, the drop down in the block contains 1, last and all, but you can replace this with your required item number. the option all will delete every item from your list (essentially emptying the list), and this is something I would recommend that you do before at the beginning of your scripts. Generally you will always want your scripts to work with an empty list. The code block below shows how to delete an item from a list.

Replacing items in a List

A nice feature provided in Scratch is the ability to replace an item in a list with something else. This is basically the same as performing the following two things:

1. Remove an item at a specific position
2. Insert an item at a specific position

The replace does this for us using the replace block. We simply provide the replace block with the location of the item in the list we wish to replace, and the item to replace it with. For example, again if we use our list given at the beginning of this post and we could replace Oranges at position 2 with Pears by simply using the block:

A slightly more complete script block could be as follows:

What else can we do with a List?

So, we have covered Inserting, Adding, deleting and Replacing items in a list, what else can we do? There are three more important things we can do with a list, these are:

1. Get an item at a specific position
2. Get the length of a list
3. Search a list for an item

Again, as with all the other list functions, there are blocks that allow us to do the three things. Lets have a look at these in order.

Getting an item at a specific position

Say we want to display an item at a specific position in the list, we use the item block. With this block, we specify the position of the item we want to return and this can then be stored in a variable or you can display it, etc. For our example we will display item number 3 (Grapes in our original list). To do this, we can use the following code block:

Getting the length of a list

As I’ve already mentioned, the size of a list is dynamic, meaning that the more you add, the bigger it becomes and there will come a time when you want to find out just how long your list is. You can find out the length of your list by using the length of block. In the same way you can return an item in a list to a variable, you can return the length of your list to a variable or again, display it. So, to display the length of our shopping list, we could use the following code block:

Search a list for an item

Finally, we can search a list for an item. As you can imagine this is a very useful thing to be able to do. You can do this by using the contains block. The code block below, shows an very simple example of searching for an item in your list.

Conclusion

This has been a brief introduction to using lists in Scratch. I do hope you find it useful. Feel free to comment on this, use it in your teaching or any way you see fit.

Variables in Scratch allow us to store a single piece of data that we can use in our scripts. This blog post will introduce Lists (also known as arrays in other programming languages). Where variables allow us to store a single piece of information, lists allow us to store multiple pieces of information in the… ]]>