Intro to Arrays COMPUTER GAME DESIGN FAIRPORT HIGH SCHOOL.

Slides:



Advertisements
Similar presentations
Why not just use Arrays? Java ArrayLists.
Advertisements

Noadswood Science,  To understand the flow procedure when writing programs Thursday, January 15, 2015.
RAPTOR Syntax and Semantics By Lt Col Schorsch
JavaScript Arrays Arrays allow us to store lists of items Arrays are created with square brackets:  var a = []; // an empty array  var b = [10]; // an.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Pie, Bar, and Line. Pie charts are best used to represent _____________________PERCENTAGES (%) The whole circle equals _____________ Because of this we.
Slides prepared by Rose Williams, Binghamton University Chapter 14 Generics and the ArrayList Class.
25 October Conditionals and Loops. Presentations Brendan: Cyberwarfare Casey: Online shopping (No current event today)
Arrays. A problem with simple variables One variable holds one value –The value may change over time, but at any given time, a variable holds a single.
Skip Counting Counting by 2, 5, and 10.
Arrays. A problem with simple variables One variable holds one value –The value may change over time, but at any given time, a variable holds a single.
Adding First, you need to know… Associative Property of Addition When: (a + b) + c = a + (b + c) Commutative Property of Addition When: a + b= b + a.
MAIN MENU Let’s learn how to add! 1+1 Video Quiz time! Great job everyone!
JavaScript Switch Statement. Switch JavaScript Switch Statement If you have a lot of conditions, you can use a switch statement instead of an if…elseif…
CMPT 120 Lists and Strings Summer 2012 Instructor: Hassan Khosravi.
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.
Loops Doing the same thing over and over and over and over and over and over…
Repeating and Growing Patterns
Python November 28, Unit 9+. Local and Global Variables There are two main types of variables in Python: local and global –The explanation of local and.
Find the perimeter of these shapes. 3 cm 8 m 7 m 10 m 25 miles.
Green Meadow Elementary
Week 7. Lecture 2 Functions, Arrays, PHP&MySQL. Function with More than one argument and a return statement For a function to return a value, the return.
Arrays, date, random. Declared Variables Explicitly define them Can give them starting values Figures out type Case sensitive var x = 5; (note: this is.
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
Arrays 1 Multiple values per variable. Why arrays? Can you collect one value from the user? How about two? Twenty? Two hundred? How about… I need to collect.
Color on Computers. Bits and Bytes Bit: a single piece of yes/no or 0/1 data Two bits can code 4 items (00, 01, 10, 11) Three bits = 8 (000, 001, 010,
Collecting Things Together - Lists 1. We’ve seen that Python can store things in memory and retrieve, using names. Sometime we want to store a bunch of.
Built-in Data Structures in Python An Introduction.
Is this a square or a pentagon? It is a square.
Loops & Graphics IP 10 Mr. Mellesmoen Recall Earlier we wrote a program listing numbers from 1 – 24 i=1 start: TextWindow.WriteLine(i) i=i+1 If.
ActionScript: For Loops, While Loops, Concatenation and Arrays MMP 220 Multimedia Programming This material was prepared for students in MMP220 Multimedia.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
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.
Using Lists Games Programming in Scratch. Games Programming in Scratch Extension – Using Lists Learning Objectives Create a temporary data store (list)
Ms. Lee’s Fraction Pizza Shop. What is a fraction? It is easy to count these pizza pies! But how do we count only part of a pizza?
Structuring Data: Arrays ANSI-C. Representing multiple homogenous data Problem: Input: Desired output:
= 5 = 2 = 4 = 3 How could I make 13 from these shapes? How could I make 19 from these shapes? STARTER.
More Sequences. Review: String Sequences  Strings are sequences of characters so we can: Use an index to refer to an individual character: Use slices.
2.6-2: Graphing Circles, Circles around Us. Recall… Standard Form: (x-h) 2 + (y-k) 2 = r 2 – Radius = r – Center (“Centre”) = (h, k)
Arrays-. An array is a way to hold more than one value at a time. It's like a list of items.
CS190/295 Programming in Python for Life Sciences: Lecture 6 Instructor: Xiaohui Xie University of California, Irvine.
The Accumulator Pattern Summing: Add up (“accumulate”), e.g. 1 2 plus 2 2 plus 3 2 plus … plus Variation: Form a product (instead of sum), e.g.
Python Programing: An Introduction to Computer Science
Steps for Solving Problem Solving in Linear Systems of Equations Read and try to formulate a visual picture of what the problem is talking about.
Week 6 - Friday.  What did we talk about last time?  Loop examples.
Introduction to TouchDevelop Lesson 3 – Comments & Lists Created by S. Johnson
Today’s Activity Solving Multi-Step Equations. Instructions You should have a baggie of colored strips. Using the strips provided, have each person of.
Introduction to Arrays. Learning Objectives By the end of this lecture, you should be able to: – Understand what an array is – Know how to create an array.
Pre-k Math activities By the end of the second Trimester, Pre-kinder students should: Identify and name numbers from 1 to 8 (in English) Count sequence.
Functions. functions: a collection of lines of code with a name that one can call. Functions can have inputs and outputs.
FLAGS. What is a Flag? A flag is a piece of cloth that has different shapes or colors on it. They are used to tell people that they: 1) Own a piece of.
Algorithm Analysis with Big Oh ©Rick Mercer. Two Searching Algorithms  Objectives  Analyze the efficiency of algorithms  Analyze two classic algorithms.
Programming in Processing Taught by Ms. Madsen Assistants: Ms. Fischer and Ms. Yen Winsor School, 2/20/08.
INTRODUCTION TO COMPUTER SCIENCE. SNAP! Open Chrome Whack a Mole Phone App in 3 minutes
 Movieclip symbols are reusable pieces of flash animation  consisting usually of one or more graphic/button symbols  thus they are flash movies within.
Colors and Shapes By: Laura Buchanan.
Introduction to Arrays
Working with Collections of Data
Learning to program with Logo
Skip Counting Counting by 2, 5, and 10.
Follow Directions with Colors and Shapes
Creation, Traversal, Insertion and Removal
Skip Counting Counting by 2, 5, and 10.
Data Structures – 1D Lists
Basics of Classification
Programming Control Structures with JavaScript Part 2
Loops and Arrays in JavaScript
For loops Taken from notes by Dr. Neil Moore
Shapes.
Presentation transcript:

Intro to Arrays COMPUTER GAME DESIGN FAIRPORT HIGH SCHOOL

Arrays A collection of data organized under a single variable name. Let's imagine you are jotting down a list on a piece of paper. Let's call the piece of paper "groceries". Now, in the paper, you write a numbered list with all the items that belong there. Start numbering from zero and enter an item that you need to purchase.

Array: VARIABLE - VALUES The piece of paper called "groceries" is your array variable. The items that you need to purchase are called the array values. Banana-Rice Pie 0 – bananas 1 – milk 2 – rice 3 – lemons

ActionScript3 var grocery:Array = new Array(); trace(grocery.length); var grocery:Array = new Array("bananas", "milk", "rice", "lemons"); trace(grocery.length);

ActionScript3 var grocery = ["bananas", "milk", "rice", "lemons"]; trace(grocery);

Adding Items to the End of Your Array The Potatoes!!! We forgot the POTATOES … The array must grow. There are several ways to add items to your array: One way would be to manually enter the index number of your array and assign a value as well. If you were to, say, add an item called "potatoes" to your current list of 4 items, simply add the following code: ?

Adding Items to the End of Your Array grocery[4] = "potatoes"; trace(grocery);

Adding Items to the End of Your Array OH NO!!!! … THE BUTTER! We need to add butter to the end of the array. You could manually enter the index position and assign a value at that position. Instead, we will try a more effective way. The new method of adding items to your array would be applied by using the length function to find out the length of the array. Once the length has been found, you can tell Flash to add an item to the end of the array without you having to manually enter the index position.

Adding Items to the End of Your Array var i = grocery.length; grocery[i]="butter"; trace(grocery); In the above code, the variable "i" gets the length of the array grocery. In the second line, the value of the length of the array is set as the index position of your grocery array.

Arrays You should take care to note that the length function simply counts the number of items in your array, and it does not start at zero; it starts at 1. Therefore, the value of the length is always one more than the index position of the last item in your array.

Arrays How can we use an Array in developing our games?

Replacing Items In Your Array Replacing items in your array is fairly simple. Let's say you aren't happy with your second entry in your grocery list. In Flash terms, you want to replace the second item in your grocery array with something else. The code for that would be: grocery[1]="tangerines"; trace(grocery); The second item, of course, has an index of 1, and the previous value for said position has now been overwritten with "tangerines."

Creating an Array by Combining Two Arrays Flash allows you to create a new array by combining the values of two other arrays. var colors = ["blue", "yellow", "green"]; var shape = ["square", "triangle", "circle"];

Creating an Array using Slice() Slice() creates a new array by extracting a specified range of values from another array. For example, let's take the following array: var countries = ["germany", "italy", "norway", "finland", "united states", "india"]