Variables.

Slides:



Advertisements
Similar presentations
 Variables  What are they?  Declaring and initializing variables  Common uses for variables  Variables you get “for free” in Processing ▪ Aka: Built-in.
Advertisements

Lets Play Catch! Keeping Score in Alice By Francine Wolfe Duke University Professor Susan Rodger May 2010.
Repetition Structures
Code Club Session 3 Shark Eats Fish. Picture of finished product here.
Scratch Programming Session 9 of 10 Review elements to use in stories, games, etc.
Calvin and Hobbes Teach Properties and Functions Created by Daniel MacDonald under the direction of Professor Susan Rodger Duke University June 2013.
Shorter of two objects and changing color Functions, events and setting the color Susan Rodger, Duke University June 2008.
Line up By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Tutorial for Arrays and Lists By Ruthie Tucker. Description This presentation will cover the basics of using Arrays and Lists in an Alice world This presentation.
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.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Nonvisual Arrays and Recursion by Chris Brown under Prof. Susan Rodger Duke University June 2012.
VB Games: Preparing for Memory Brainstorm controls & events Parallel structures (again), Visibility, LoadPicture, User-defined procedures, Do While/Loop,busy.
By Melissa Dalis Professor Susan Rodger Duke University June 2011 Multiplication Table.
Game Maker Terminology
Making a Timer in Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University July
Variables and Inheritance Part 1
Piñata Game: Keeping Score in Alice By Maggie Bashford Professor Susan Rodger Duke University July
Sanjay Johal. Introduction(1.1) In this PowerPoint I will be explaining :  The purpose of the code for each of the two given programs, e.g. to carry.
Can I get your number? By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running Types of data.
For slides 2 to 12, count the change as the coins and bills appear on the screen. Before clicking the final answer, count the change to yourself to see.
Balancing the scales: Inequalities By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Tutorial for Arrays and Lists. Description This presentation will cover the basics of using Arrays and Lists in an Alice world It uses a set of chickens.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
CompSci 4 Chap 6 Sec 2 Sep 30, 2010 Prof. Susan Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were not a Flutterbudget.
How to add Word-Art to a Word Document Purpose: To learn how to add WordArt to a Word Document.
Class-Level Variables in Alice
Chapter 3: Variables, Functions, Math, and Strings
Putting Objects in Motion
Three Minute Timer Two Minute Timer One Minute Timer
Changing Color, Using Text Objects, and Random Selection in Alice
Control Structures
Let's Race! Typing on the Home Row
Introduction to Object-Oriented Programming
Learning Objective LO: We’re learning to understand when it is appropriate to use particular data types.
Stopwatch Cards Stopwatch Cards
A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 13 (Reed) - Conditional.
By Sanjay and Arvind Seshan
Alice Learning to program: Part Three By Ruthie Tucker and Jenna Hayes, Under the direction of Professor Rodger Duke University, 2008.
Learning PowerPoint Just the basics.
Michelle Venable-Foster Barb Ericson Jan 2007
Sensing and Variables.
By Sanjay and Arvind Seshan
CIS 16 Application Development Programming with Visual Basic
Stopwatch Cards Stopwatch Cards
Using Functions
Restricting an Event with a Conditional
100,000 Pyramid How to setup the game:
Variables and Inheritance Part 1
Introduction to Object-Oriented Programming in Alice
Using Lists and Functions to Create Dialogue
Ways to make a nice looking PowerPoint!
ICT Gaming Lesson 3.
1,000,000 Pyramid How to setup the game:
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Stopwatch Cards Stopwatch Cards
Game Over Module 4 Lesson 2.
Tutorial for Arrays and Lists
Stopwatch Cards Stopwatch Cards
Directions: For slides 2 to 12, count the change as the coins and bills appear on the screen. Before clicking the final answer, count the change to yourself.
1,000,000 Pyramid How to setup the game:
Sensing and Variables.
A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 13 (Reed) - Conditional.
CSC 221: Introduction to Programming Fall 2018
Stopwatch Cards Stopwatch Cards
under the direction of Professor Susan Rodger
Restricting Events Creating Conditional Events in Alice By Henry Qin
Stopwatch Cards Stopwatch Cards
Presentation transcript:

Variables

What will we learn today? What Are Variables Variables in Real-Life Variables in Programs Types of Variables Creating a Timer Example

Variables A Variable is a storage location (place in computer’s memory) which contains information Variables are analogous to "Buckets" or "Envelopes" where information can be maintained and referenced Each variable has a name (an identifier), a type and a value (piece of information) E.g. (a=5, b=“hello”) Variables allow us to keep track of changes as our program runs

Variables in Real Life We use variables to track the balance of money in a bank account We use variables to track the amount of gasoline in the tank of the car

Variables in Programs We often need to keep track of changes in position, color, and other properties of objects in our programs In a game, we may want to keep track of number of steps or times or numbers of goals..etc For example, we want to know the number of times a player has put the basketball through the hoop or how much time is left on the clock

Types of Variables Numeric Boolean Character/String Object They can store a whole number value, e.g. 7 or 1024 Boolean They can represent one of two states, true or false Character/String They can represent a single character, e.g. 'A' or '$‘ or a group of characters, e.g. “Ali” or “20 minutes left” Object They can represent a whole object, e.g. cat or fort

A Timer for a Game Example A timer is used in most of the games to keep track of how much time the player has left to play We will construct a timer that counts down in seconds Our task is to set the timer to an initial number of seconds (e.g. 10s) and then count down the seconds remaining in a game The number of seconds remaining will be displayed and will be updated with each passing second We will create a chicken that rotates around itself as the timer count down

A Timer for a Game Example Add a new object: a 3D text Type 0.0 which is the value that appears when the time’s over

A Timer for a Game Example Rename the object to timer

A Timer for a Game Example Add a new variable in the timer object Select the timer object Select the properties tab Click on the ‘create new variable’ button Name it ‘timeLeft’ and set it to type ‘number’

A Timer for a Game Example Drag the ‘timeLeft’ to the ‘world.timer’ method Create a new parameter and call it ‘amount of time’

A Timer for a Game Example Set the values as shown Create a new method and call it ‘countDown’

A Timer for a Game Example Inside the method, add a while loop with expression ‘a<b’ and set ‘a’ and ‘b’ as follows Drag the text inside the while loop

A Timer for a Game Example Set the value of the text as follows, drag ‘what’ from the functions box Drag time left from properties insert it into the what box

A Timer for a Game Example Move the timer up and down Make a function that returns the time left

A Timer for a Game Example The ‘countDown’ method Create a method ‘playGame’ and set it as follows

A Timer for a Game Example The main method ‘world.myFirst’ method

A Timer for a Game Example Here is our Chicken

Let’s Work with Alice Counting Fishes A Scuba diver (people) wants to count the fishes (ocean) that eat from the Seaweed (ocean). Make a method where each fish goes to the seaweed, eats, waits, and comes back. As each fish does so, a counter on the top-right corner of the screen (3D-Text) increases by one. After all fish have eaten, the scuba diver says the final count of fishes. You will need to create a number variable ‘NumberOfFish’ for that.