pset 0: scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · variables broadcasting ... in...
TRANSCRIPT
![Page 2: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope](https://reader034.vdocument.in/reader034/viewer/2022042710/5f6806f4b7b9da275217c0cc/html5/thumbnails/2.jpg)
Scratch
![Page 3: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope](https://reader034.vdocument.in/reader034/viewer/2022042710/5f6806f4b7b9da275217c0cc/html5/thumbnails/3.jpg)
Toolbox
Sprites & costumes
Stage & backgrounds
Conditions
Loops
Variables
Broadcasting events
Threads
![Page 4: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope](https://reader034.vdocument.in/reader034/viewer/2022042710/5f6806f4b7b9da275217c0cc/html5/thumbnails/4.jpg)
Sprites
Every object is a sprite.
Two cats ⇒ two sprites
Sprites have:
Scripts (how the sprite ‘behaves’)
Costumes (what the sprite looks like)
![Page 5: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope](https://reader034.vdocument.in/reader034/viewer/2022042710/5f6806f4b7b9da275217c0cc/html5/thumbnails/5.jpg)
Stage
Where all sprites are placed
The stage can also have scripts
Useful when scripts aren’t specific to an actual sprite
Instead of costumes, has backgrounds.
![Page 6: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope](https://reader034.vdocument.in/reader034/viewer/2022042710/5f6806f4b7b9da275217c0cc/html5/thumbnails/6.jpg)
Creating Scripts; Entry Point
Begin the program with pressing the green flag.
![Page 7: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope](https://reader034.vdocument.in/reader034/viewer/2022042710/5f6806f4b7b9da275217c0cc/html5/thumbnails/7.jpg)
Statements
Where the action is
![Page 8: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope](https://reader034.vdocument.in/reader034/viewer/2022042710/5f6806f4b7b9da275217c0cc/html5/thumbnails/8.jpg)
Booleans, Conditions
Ask a true/false question…
…And do something based on the answer.
![Page 9: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope](https://reader034.vdocument.in/reader034/viewer/2022042710/5f6806f4b7b9da275217c0cc/html5/thumbnails/9.jpg)
Loops
Used to repeat statements
Continuously
For a set number of times
Until a certain condition is true
![Page 10: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope](https://reader034.vdocument.in/reader034/viewer/2022042710/5f6806f4b7b9da275217c0cc/html5/thumbnails/10.jpg)
Avoid this:
![Page 11: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope](https://reader034.vdocument.in/reader034/viewer/2022042710/5f6806f4b7b9da275217c0cc/html5/thumbnails/11.jpg)
Much better!
![Page 12: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope](https://reader034.vdocument.in/reader034/viewer/2022042710/5f6806f4b7b9da275217c0cc/html5/thumbnails/12.jpg)
Variables
Contain values
In Scratch: Numbers and words
![Page 13: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope](https://reader034.vdocument.in/reader034/viewer/2022042710/5f6806f4b7b9da275217c0cc/html5/thumbnails/13.jpg)
Variables: Scope
Global (stage + all sprites)
Local (one sprite only)
Who needs to use the variable?
![Page 14: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope](https://reader034.vdocument.in/reader034/viewer/2022042710/5f6806f4b7b9da275217c0cc/html5/thumbnails/14.jpg)
Events
How the sprite behaves when…
![Page 15: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope](https://reader034.vdocument.in/reader034/viewer/2022042710/5f6806f4b7b9da275217c0cc/html5/thumbnails/15.jpg)
Broadcasting events
Allows sprites to communicate
Signal an event:
Handle an event:
![Page 16: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope](https://reader034.vdocument.in/reader034/viewer/2022042710/5f6806f4b7b9da275217c0cc/html5/thumbnails/16.jpg)
Threads
Simultaneous processes
![Page 17: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope](https://reader034.vdocument.in/reader034/viewer/2022042710/5f6806f4b7b9da275217c0cc/html5/thumbnails/17.jpg)
Example: Hungry Shark
![Page 18: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope](https://reader034.vdocument.in/reader034/viewer/2022042710/5f6806f4b7b9da275217c0cc/html5/thumbnails/18.jpg)
HungryShark 0
Shark moves off screen
Chomp action
Fish movement
![Page 19: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope](https://reader034.vdocument.in/reader034/viewer/2022042710/5f6806f4b7b9da275217c0cc/html5/thumbnails/19.jpg)
HungryShark 1
Chomp, revisited
Score updates
![Page 20: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope](https://reader034.vdocument.in/reader034/viewer/2022042710/5f6806f4b7b9da275217c0cc/html5/thumbnails/20.jpg)
HungryShark 2
Eating a poisonfish makes the shark sick
Game over feature
![Page 21: pset 0: Scratchcdn.cs50.net/2012/fall/psets/0/walkthrough0.pdf · Variables Broadcasting ... In Scratch: Numbers and words . Variables: Scope](https://reader034.vdocument.in/reader034/viewer/2022042710/5f6806f4b7b9da275217c0cc/html5/thumbnails/21.jpg)
this was walkthrough 0