Using Lists Games Programming in Scratch. Games Programming in Scratch Extension – Using Lists Learning Objectives Create a temporary data store (list)
Post on 19-Jan-2016
214 Views
Preview:
Transcript
Using ListsGames Programming
in Scratch
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
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
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
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
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
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?
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
Games Programming in ScratchExtension – Using Lists
Recalling the items in a list• Simple method:
• Loop method:
Games Programming in ScratchExtension – Using Lists
Comment your Code• Add comments to your code to help explain
what each part does
top related