Using Lists Games Programming in Scratch. Games Programming in Scratch Extension – Using Lists...

10
Using Lists Games Programming in Scratch

Transcript of Using Lists Games Programming in Scratch. Games Programming in Scratch Extension – Using Lists...

Page 1: Using Lists Games Programming in Scratch. Games Programming in Scratch Extension – Using Lists Learning Objectives Create a temporary data store (list)

Using ListsGames Programming

in Scratch

Page 2: Using Lists Games Programming in Scratch. Games Programming in Scratch Extension – Using Lists Learning Objectives Create a temporary data store (list)

Games Programming in ScratchExtension – Using Lists

Learning Objectives• Create a temporary data store (list) to hold

multiple items• Add items to the list• Keep count of the number of items in the list• Use the items in the list

Page 3: Using Lists Games Programming in Scratch. Games Programming in Scratch Extension – Using Lists Learning Objectives Create a temporary data store (list)

Games Programming in ScratchExtension – Using Lists

Starter• How do you remember things you need

to buy at a supermarket?• How will you know when you have got all

the items?• How would you get a computer to check

you have them all?• Write some simple instructions for this

Page 4: Using Lists Games Programming in Scratch. Games Programming in Scratch Extension – Using Lists Learning Objectives Create a temporary data store (list)

Games Programming in ScratchExtension – Using Lists

Shopping ListsRepeat

Think of itemAdd item to list

Until you can’t think of any more itemsRepeat

Look at first item in listCheck item is in basketIf item not in basket then

Get itemElse tick item

Until end of list

Page 5: Using Lists Games Programming in Scratch. Games Programming in Scratch Extension – Using Lists Learning Objectives Create a temporary data store (list)

Games Programming in ScratchExtension – Using Lists

Variables or Lists• Variables are great for individual pieces of

information like scores, lives and health. • However, sometimes we want to store a list of

information. For example, in an RPG game you might want to keep a list of the items you have collected in your bag.

• For this, you need to use a LIST

Page 6: Using Lists Games Programming in Scratch. Games Programming in Scratch Extension – Using Lists Learning Objectives Create a temporary data store (list)

Games Programming in ScratchExtension – Using Lists

What is a List in Scratch?• In Scratch, a List is a special variable type that

can contain multiple other variables.• In other programming languages this is usually

known as an Array

Page 7: Using Lists Games Programming in Scratch. Games Programming in Scratch Extension – Using Lists Learning Objectives Create a temporary data store (list)

Games Programming in ScratchExtension – Using Lists

Using Lists• Build an inventory/bag into your game• Write out the instructions (on some paper or a

whiteboard) for what happens:-– If your main character comes into contact with a

collectable item– When you want to use an item in your

inventory/bag• Compare your instructions with those of your

peers. Will they work as intended?

Page 8: Using Lists Games Programming in Scratch. Games Programming in Scratch Extension – Using Lists Learning Objectives Create a temporary data store (list)

Games Programming in ScratchExtension – Using Lists

Challenge!• Try to implement your instructions• Modify your game so that you can collect

items and add them to your inventory/bag

Page 9: Using Lists Games Programming in Scratch. Games Programming in Scratch Extension – Using Lists Learning Objectives Create a temporary data store (list)

Games Programming in ScratchExtension – Using Lists

Recalling the items in a list• Simple method:

• Loop method:

Page 10: Using Lists Games Programming in Scratch. Games Programming in Scratch Extension – Using Lists Learning Objectives Create a temporary data store (list)

Games Programming in ScratchExtension – Using Lists

Comment your Code• Add comments to your code to help explain

what each part does