400 likes | 499 Views
Alice Workshop. Implementation Algorithm Code World.my first method Control blocks Statements (methods, data, more). Next Step. Problem Statement. Understand the problem. Test the code. Design a solution. Implement the design. Load World.
E N D
Alice Workshop Implementation Algorithm Code World.my first method Control blocks Statements (methods, data, more)
Next Step Problem Statement Understand the problem Test the code Design a solution Implement the design
Load World • Why start with a standard world for active learning? • Load from: Presentations/Worlds 3-GoodVibrationsSetUp.a2w
Do in order By default, statements in the code are performed in order, but you can also create a Do in order code block.
Control Statements • Alice has two fundamental control statements • Do in order • perform the actions in sequence • Do together • perform the actions simultaneously
1. Select object • Start by selecting an object in the object tree (or click on the object in the scene)
2. Select methods tab • Tabs • Properties values of object properties • Procedures methods that perform an action • Functions methods that return a value • In the details panel
3. Find method tile • Scroll down in methods tab
4. Drag-n-drop Select data from drop-down menu… “turn to face” needs a target object
Next Step Problem Statement Understand the problem Test the code Design a solution Implement the design
Play (Run) • Click the Play button
World.my first method • When Play button is clicked, the world’s my first method is executed
Modify • Alice allows some optional information to modify how an action is performed. • By default a statement in Alice runs in 1 second. The duration can be changed using more…
Next action • Actually, several actions
Method? • No “vibrate” tile? • Method tiles built-in to Alice are simple actions • Some models have complex actions defined, e.g., walk • For other complex actions, we may create our own
Decompose • How can we create our own “vibrate” method? • Decompose a complex action into simple actions garfield.vibrate do together play vibrating sound do in order garfield move up a short distance, quickly garfield move down same distance, quickly
Name the method • Name should begin with a lowercase letter and have no spaces (use camelCase, if needed)
garfield.vibrate • New method tile and editor tab
Number pad • Select “other” for number pad entry
Duplicate • Hold Ctrl(Alt on Mac) and drag statement down to create a duplicate
Modify • Click drop-down menu to select a different (argument) value
Test Warning???
Call the method • Alice must be given an instruction to perform the actions defined in the method.
Test Does the action performed by garfield appear to be a vibration? Why or why not?
Revise Design • An object that vibrates is oscillating in a rhythmic repetition • We need to repeat the action several times garfield.vibrate do together play vibrating sound repeat 5 times do in order garfield move up a short distance, quickly garfield move down same distance, quickly
Loop • Drag in Loop control tile and select “5 times”
Loop control block • Drag code statements into the Loop control block • A block of program code that repeats a counted number of times.
Test Does the action performed by garfield appear to be a vibration? Why or why not?
Revise #2 • Play a sound at the same time…. garfield.vibrate do together play vibration sound loop 5 times garfield moves up a short distance, quickly garfield moves down same distance, quickly
Import sound • World properties panel
Do together • Drag in do together code block
Nested control blocks • Do in order inside do together
Test • Are sound and vibration in sync?
Wait • Useful for synchronizing sound and action
Save • Be sure to save the world every half-hour, or so…
Textbook • More information • Coding • Chapter 2, Section 2