Download presentation
Presentation is loading. Please wait.
1
August 31 Intro to CS
2
Today’s Objectives Hand in Homework Assignment Review last class Today
If/Then/Else Parallelism Debugging How to deal with SNAP! edges
3
Review: Make Block or Right click on empty space in Script Area
this dialog box will appear. or Press “Make Block” button in Variables and this dialog box will appear.
4
Two “Looks” commands – goto front , go back N layers
Front, -2 layers Front, -1 layer Front layer With these 2 commands, you can control where the scenery resides.
5
Stage scripting Click on Stage icon Scripts just like for Sprites
Broadcast messages This runs Mario Sprite only which is useful for debug
6
Today’s Objectives Hand in Homework Assignment Review last class Today
Loops: If; If/Else; Repeat; Forever Parallelism Debugging How to deal with SNAP! edges
7
“Loops”: If/Else/Repeat
Notice how the bottom is flat? This script ends here and does not move on. The contents inside will repeat until the condition is met. Repeat the # of times in the box. Then moves to the next block Executes if evaluation of Boolean expression is True. If not, it moves to the next block. Executes if evaluation of Boolean expression is True. If not, it executes the contents of “else”.
8
Lab: Model the ‘aRoomLightOn’ Boolean expression in SNAP
Lab: Model the ‘aRoomLightOn’ Boolean expression in SNAP! (aRoomLightOn = pgePower AND (floorLamp OR tableLamp ) Create three variables: pgePower, floorLamp, tableLamp Initialize all three variables to be ‘false’ Say “The variables are initialized.” Broadcast a “Initialized” message Start when “initialized” message is received Create a Boolean expression that tests each variable for “true” Use an If/Else statement If expression = “true”, say, “The light is on” If expression is not = “true”, think, “Hmmm. I wonder when the light will turn on.”
9
Lab: ANSWER
10
Parallelism ( also called threads)
These are 5 different streams of instructions/code also called threads. Program Counter can’t be in 5 different places at the same time!! SNAP executes a few instructions in one stream and then moves to the next. 1 GHz = 1,000,000,000 instructions in 1 second Makes it appear that each stream/thread is executed simultaneously.
11
Debugging A methodical process of finding and reducing the number of defects (bugs) in a computer program, making it behave as expected.
12
You need to know where the program stops working.
Debugging Who do you find them? You need to know where the program stops working. How do you do that?
13
Debugging Here are a couple methods:
Insert a block before and after the section of code that you think has the problems. (Be sure and remove them after you have solved the problem.)
14
Debugging You can also isolate the problem by running just he block or script itself. Click on the block or script. Duplicate the block to get it out of the script.
15
Debugging Finally, you can display global, local and system variables on the stage.
16
Debugging - Help Right click on desired instruction.
Pops up a drop-down menu. Click on “help”.
17
Debugging - Help The Help dialog box pops up.
Has and explanation and ... A code example!!!
18
Lab: Debug ‘August31Labs - aRoomLightOn’ (There are 3 bugs planted.)
Type this into your browser, all on one line with no spaces or breaks: Username=johngoble&ProjectName=Aug31Labs-v3
19
Lab: Debug ‘PowerOnLabs’-ANSWER
20
Dealing with EDGES in Mario – using Blocks, of course
Let’s write some code which deals with a Sprite at the edge. Two choices – The Sprite can wrap or bounce.
21
Dealing with EDGES in Mario continued
Question: Why use a CustomBlock rather than a stack of SNAP! blocks from the palette?
22
Dealing with EDGES in Mario continued
Question: Why use a CustomBlock rather than a stack of SNAP! blocks from the palette? Answer: A stack of SNAP! blocks from the palette requires me to cut and paste the stack 4 times for each of the 4 Sprit I must fix a bug in 4 places instead of 1 place: Custom Block Also, 4 Stacks of the same code consumes too much screen area
23
Edges - Make Block Dialog box appears Give it a name Press OK
Right click in Script area/Press MakeBlock button Dialog box appears Give it a name Press OK
24
Edges continued Click on “+” sign Name the input - bWrap
LowerCase “b” reminds me it’s Boolean i.e. true or false. – not a number Click OK
25
Edge Logic bWrap = true If past Right Edge Wrap If not do nothing
bWrap = false Let SNAP make it bounce. Click OK
26
Reminder of Stage Geometry
27
Test it!! I used “MakeVariable” to create 3 variables – LeftEdge
RightEdge bWrapOrBounce Why is the “move 2 steps” not inside the CustomBlock? Let’s see it work!
28
Demo
29
Edge exercise - get ready
Question: Why should CustomBlock be global but variable bWrapOrBounce be local?
30
Edge exercise - get ready
Question: Why should CustomBlock be global but variable bWrapOrBounce be local? Answer : CustomBlock should be global so Mario, Tree , Gremlin and Mountain can use it. bWrapOrBounce should be local( this Sprite only) so that each Sprite can have individual behavior at the edge – Wrap or Bounce.
31
Lab: Edge exercise – 30 minutes
Extend my example to both left and right edges. Your code should be able to Wrap or Bounce based on an input variable. When your code works “Save it” so you can use it on your Mario projects.
32
Open Lab Work on your project
33
Review of Today’s Topics
Loops: If; If/Else; Repeat; Forever Custom Block w/input for Edge behavior Debugging
34
Reminders Read Chapter 2*
before the start of class on Monday, September 12 *NOT just the excerpt Test will be Friday, Sept 9 on computer parts and SNAP!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.