Making a Timer This is an modification of the July 2008 timer tutorial by Jenna Hayes By Natalie Huffman Under the direction of Susan Rodger Duke University.

Slides:



Advertisements
Similar presentations
Getting Started With Alice: The Basics By Jenna Hayes under the direction of Professor Susan Rodger Duke University July
Advertisements

Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010 modified July 2011.
Alice Learning to program: Part Four Creating Sounds, Making Billboards, Fun with 3-D Text, New Events, and Rotating Objects by Ruthie Tucker and Jenna.
Getting Started With Alice By Ruthie Tucker under the direction of Prof. Susan Rodger Duke University, July
How Tall Are You? Introducing Functions By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008 Updates made June 2014 by.
Using Functions in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University July 2008.
Lets Play Catch! Keeping Score in Alice By Francine Wolfe Duke University Professor Susan Rodger May 2010.
Using Functions in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University July 2008.
Code Club Session 3 Shark Eats Fish. Picture of finished product here.
Class-Level Variables in Alice By Jenna Hayes Under the direction of Professor Rodger Duke University, July 2008.
Wizard Game: Class-Level Variables in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July
Creating a 3D Interactive Story Prof. Susan Rodger Duke University Feb. 24, 2007.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Making a Timer in Alice.
Making a Boat Racing Game in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2010.
Shorter of two objects and changing color V2 Functions, events and setting the color in sequence and randomly This is a modification of the Changing Color.
Getting started with Alice Adapted from presentations by Jenna Hayes, Duke University Donna Gavin, UWP Computer Science and Software Engineering.
Changing Color, Using Text Objects, and Random Selection in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2008.
An Introduction to Alice (Short Version) – Extras! Yossra Hamid Under the Supervision of Professor Susan Rodger Duke University, June 2014 This is a continuation.
Making a Timer in Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University July
Alice Learning to program: Part Two Writing Your Own Methods by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University,
The Essentials of Alice (Bunny) By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008.
Illuminating Computer Science CCIT 4-6Sep
Balancing the scales: Inequalities By Melissa Dalis Professor Susan Rodger Duke University June 2011.
The Essentials of Alice Mrs. Jayne Slease SBMS CTE Computer Science and Animation Credit to Duke Students under the direction of Professor Susan Rodger.
Creating a 3D Interactive Story Prof. Susan Rodger Duke University July 19, 2007.
Tutorial on Kangaroo visiting his animal friends - parameters, events Susan Rodger Duke University June 2009.
Learning to Program: Part 1 Scene Setup and Starting Animation by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University,
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010.
How Tall Are You? Introducing Functions for Alice 3 By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008 Updates made.
The Essentials of Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University May 2009.
Getting Started With Alice: The Basics. Step 1: Background Open up Alice, and choose a background for your Alice world. Your world is something you can.
Tutorial on Bunny visiting his animal friends - parameters, events for Alice 3 Susan Rodger Duke University June 2009 Updated by Yossra Hamid on October.
Under the direction of Susan Rodger
Jonathon Kuo Under the Direction of Dr. Susan Rodger
By Melissa Dalis Professor Susan Rodger Duke University June 2011
The Essentials of Alice (Bunny)
Getting Started With Alice: The Basics
Weebly Elements, Continued
A Simple Quiz for Alice 3.2:
An Introduction to Alice (Short Version)
Teaching Characters to Walk: Learning Methods, Part 1
Comparing objects and changing color
Under the direction of Susan Rodger
Changing Color, Using Text Objects, and Random Selection in Alice
Making Objects Move in Unison: Using Lists
Tutorial on Kangaroo visiting his animal friends - parameters, events
Adding and Manipulating Objects
Making Objects Move in Unison: Using Lists
Memory Matching Challenge
Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4)
A Simple Quiz for Alice 3.2:
Go to =>
Under the direction of Susan Rodger
Objects in Alice: Positioning and Moving Them
Introduction to TouchDevelop
Learn a bit about Computer Science Duke Femmes Event with Prof
An Introduction to Alice
Go to =>
Restricting an Event with a Conditional
Variables and Inheritance Part 1
How Tall Are You? Introducing Functions
Using Lists and Functions to Create Dialogue
Getting Started With Alice
Professor Susan Rodger
Getting Started With Alice: The Basics
Professor Susan Rodger
under the direction of Professor Susan Rodger
Presentation transcript:

Making a Timer This is an modification of the July 2008 timer tutorial by Jenna Hayes By Natalie Huffman Under the direction of Susan Rodger Duke University June 2017

Open a new Alice world Choose “Grass” Go to setup scene Click on the shapes/text tab at the bottom of the page Select new TextModel()

Name: timer Paint: WHITE Value: “0.0”

Create a TextModel property Select TextModel Add TextModel Property from the drop down menu Value type: DecimalNumber Name: timeLeft Initializer:0.0

Create a TextModel Procedure Select TextModel Add TextModel Property from the drop down menu Name it initialize

Initialize This procedure will establish how much time our timer starts with, so we need a parameter Set the value type as DecimalNumber Set the name as amountOfTime

Drag in the setTimeLeft method and choose “amountOfTime” timeLeft is the property we created for our textModel and it will be accessible from myFirstMethod

Create a TextModel Procedure Create another TextModel procedure by selecting TextModelAdd TextModel Procedure from the dropdown menu Name it “countDown”

countDown Drag in a while loop and choose true Then select Relational (DecimalNumber)???>???this.timeLeftCustom DecimalNumber Select 0.0 for the custom number See the next slide for a picture

Next, drag in setValue and select “hello” setValue changes the content displayed by the TextModel However, this procedure wants to be given a word, and we want to change the value to timeLeft, which is a DecimalNumber So instead, we select ???+???DecimalNumberthis.timeLeft Custom TextString When the custom string box pops up, leave it blank and hit enter This lets us set the content equal to timeLeft + “”, so Alice will automatically convert timeLeft to a string

Drag in setTimeLeft and select TimeLeft Then click the dropdown arrowMaththis.timeLeft-???1.0 Drag in delay, and select 1.0

Go back to myFirstMethod In myFirstMethod, select this.timer on the far left and drag in initialize Choose how much time you want your timer to start with! I chose 10.0 Drag in countDown Run your code!

Hang on…. Our timer ends at 1.0! Why? Go back to countDown The while loop only runs when timeLeft is greater than zero, so when timeLeft = 0, the loop ends But we want to reset the value of the TextModel one last time

Debugging Right click on the setValue line and select “copy to clipboard” Click and drag from the clipboard image on the top right Put the line of code beneath the while loop

Now run your code! The timer should stop at 0.0, just like we want it to But we made the timer a DecimalNumber for a reason—what if we want to countdown by smaller numbers? We’ll choose .1

Go back to countDown Set the two instances of 1.0 (in setTimeLeft and delay) to .1 Run your code!

Umm….. This doesn’t seem quite right You probably got something that looks like this As the timer keeps going, the error gets bigger and bigger

Quick Explanation This is essentially caused by a rounding error Computers store numbers in binary (ones and zeroes) But the number .1 can’t be represented exactly in binary It’s kind of like trying to write 1/3 in decimal; you get .3333333333 repeating on forever Alice doesn’t subtract .1, it actually subtracts .09999999999 etc, so your timer is always slightly ahead of where it should be

Luckily, we can fix this! Alice has a built in set of rounding commands, found under the Math tab Ceiling always rounds up, floor always rounds down, and round follows normal rounding rules We’ll use floor, since our number is just a little bit too big But using floor on the number 9.9000000001 will round it all the way down to 9! That’s not what we want

Click the arrow on the far rightMathabsolute value, round, ceiling, floorfloorthis.timeLeft Now click the inner arrowMaththis.timeLeft-???Custom DecimalNumber and enter .1 Now there are three arrows! Click the middle oneMath(this.timeLeft - 0.1)*???10.0 This gives us 99.000000001, and rounding will change it to 99.0, which is almost what we want! The only thing left to do is divide it back out Click the arrow on the far rightMathfloor((this.timeLeft - 0.1) * 10.0)/???10.0

Your code should look like this

Run your code Your timer should show up exactly like you wanted it to!