Navigation

    CreatiCode Scratch Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode

    Editing a List Using Blocks

    2D Blocks
    1
    1
    289
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • info-creaticode
      CreatiCode last edited by admin

      Prerequisite

      • Introduction to Lists

       

      Description

      You can easily edit a list using blocks, such as adding new items, removing some items, or changing the value of some items.

       

      Appending a New Item

      This block can be used to add a new item at the bottom of the list. The length of the list will increase by 1 each time we run this block.

       

      Parameters

      • Value: the number or text to be added. If you leave this field empty, an empty item will be added to the list.
      • List Name: select the name of the list. You need to create that list before you can choose it in this dropdown.

       

      Demo

       

      Inserting a New Item

      If you want the new item to be placed at a particular position (not at the bottom), you can use the insert block.

       

      Parameters

      • value: the number or text to be added. If you leave this field empty, an empty item will be inserted to the list.
      • Position Index: the position of the new item. For example, if the list already has 2 items, then the position index parameter can only be 1, 2 or 3.
      • List Name: the name of the list. You need to add at least one list manually first.

       

      Demo

       

      Replacing an Item

      You can change the value of an item in the list if you know its position index.

       

      Parameters

      • Position Index: the position of the item to be changed. For example, if the list already has 3 items, then the position index parameter can only be 1, 2 or 3.
      • List Name: the name of the list.
      • Value: the new value for that item, and it can be empty as well.

       

      Demo

       

      Deleting an Item by Its Position Index

      You can remove an item from the list with this block if you know its position.

       

      Parameters

      • Position Index: the position of the item to be deleted. For example, if the list already has 3 items, then the position index parameter can only be 1, 2 or 3.
      • List Name: the name of the list.

       

      Demo

       

      Deleting an Item by Its Value

      This block allows you to delete an item by its value. This is handy when you do not know the position of the item to be deleted, but you know its value.

       

      Parameters

      • Value: The value of the item to be deleted. If that value can not be found in the list, then no item will be deleted. When more than one item has this value, only the first item with this value will be deleted.
      • List Name: The name of the list.

       

      Demo

       

      Deleting All Items

      This block will delete all items in a list and make the list empty.

       

      Changing the Value of an Item

      These 2 blocks allow us to increase or decrease an item’s value by some number:

       

      Learn More

      • Reading from a List
      1 Reply Last reply Reply Quote 0
      • Pinned by  info-creaticode info-creaticode 
      • First post
        Last post