Arrays http://www.alice.org/resources/lessons/arrays/

Slides:



Advertisements
Similar presentations
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Advertisements

3D Text/Collisions CREATING THESE EFFECTS IN ALICE 3.1.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Chapter 10 Introduction to Arrays
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Case, Arrays, and Structures. Summary Slide  Case Structure –Select Case - Numeric Value Example 1 –Select Case - String Value Example  Arrays –Declaring.
SUNY Morrisville-Norwich Campus-Week 12 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
Chapter 9 Introduction to Arrays
Java Unit 9: Arrays Declaring and Processing Arrays.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
XP New Perspectives on Microsoft Office Access 2003 Tutorial 11 1 Microsoft Office Access 2003 Tutorial 11 – Using and Writing Visual Basic for Applications.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
Microsoft Visual Basic 2005 CHAPTER 9 Using Arrays and File Handling.
Using Arrays and File Handling
Introduction to Arrays. definitions and things to consider… This presentation is designed to give a simple demonstration of array and object visualizations.
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Nonvisual Arrays and Recursion by Chris Brown under Prof. Susan Rodger Duke University June 2012.
Checking for Collisions: Alternative Method Erin Taylor Under the Direction of Susan Rodger July 2015 Duke University.
VBA Lab 2 I ns.Samia Al-blwi. Visual Basic Grammar Object: Visual Basic is an object-oriented language. This means that all the items in Excel are thought.
Arrays An array is a data structure that consists of an ordered collection of similar items (where “similar items” means items of the same type.) An array.
A Simple Quiz: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009, added Part 2 July 2011.
Game Maker Terminology
1 ball, 2 ball, red ball, blue ball By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Mathematical Expressions, Conditional Statements, Control Structures
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Simple Collision Detection By David Yan Under the direction of Professor Susan Rodger and Chari Distler Duke University, June 2015.
CHAPTER 14 Classes, Objects, and Games XNA Game Studio 4.0.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
National Diploma Unit 4 Introduction to Software Development Procedures and Functions.
21/03/ Working with Controls Text and List Boxes.
Visual Basic.NET BASICS Lesson 9 Nested If Statements and Radio Buttons.
Arrays Chapter 7.
Jonathon Kuo Under the Direction of Dr. Susan Rodger
Creating a UFO Rescue Game in Alice
Programming Right from the Start with Visual Basic .NET 1/e
JavaScript, Sixth Edition
Unit 2 Technology Systems
Coupling and Cohesion Rajni Bhalla.
EGR 2261 Unit 10 Two-dimensional Arrays
Comparing objects and changing color
Chapter 3: Variables, Functions, Math, and Strings
Putting Objects in Motion
Making Objects Move in Unison: Using Lists
Control Structures
Using Procedures and Exception Handling
Introduction to Events
Object-Oriented Programming: Classes and Objects
Creating a UFO Rescue Game in Alice
While Loops BIS1523 – Lecture 12.
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Organizing common actions
Chapter 10 Programming Fundamentals with JavaScript
Data Types
Visual Basic .NET BASICS
Making Objects Move in Unison: Using Lists
Memory Matching Challenge
Making Procedural Methods
Object Oriented Programming in java
CIS 16 Application Development Programming with Visual Basic
A Guide to adding Sites and Blocks within ESTATE Manager
Webropol – Getting started 3
Using Functions
Using Parameters
Using Lists and Functions to Create Dialogue
CIS16 Application Development and Programming using Visual Basic.net
Loops and Arrays in JavaScript
Presentation transcript:

Arrays http://www.alice.org/resources/lessons/arrays/

Arrays What is an Array An array is a type of data structure that is made up of a group of information (values or variables) in an organized arrangement often depicted in a column or row. All items in an array must be of a similar data type.

Arrays An Ordered Array Alice arrays are ordered with each element in the array identified by an index number. The numbering in the list starts with 0 at the first position. The index is a way to keep track of the element being stored in that location. In this example: Fish[0] is holding the clownfish Fish[2] is holding the blue tang

Arrays Why Use an Array Arrays make it easier to store similar types of data and allows you to create programs that can perform the same function on each item in that array. In Alice this allows you to do things like: perform the same swim animation on a school of fish create an array of dialogue and randomly select from it to create different dialogue Create a group of items that all have the same collision logic on them

Arrays Where to Create Arrays There are a couple different places you can create arrays in Alice. Where you create the array will affect the type of data that can be used as well as where you will be able to access and use the array. Class Properties - This creates an array that is a part of the class itself. These arrays will be accessible in all methods of that class but will need to be passed into other class methods as a parameter. In Line - You can create an array using code inside of a method. This will make the array only accessible in that method after it has been created. Inside a Control Structure or Event - You can create an array inside of a control structure. Alice will force you to do this on occasion in order to service the control structure. Many of our events will use an array as a parameter as an optional detail.

Arrays Creating an Array As a class property - Select Add Scene Property to create a new element. This creates an array that can be used throughout the class. A scene property array can be accessed in all scene methods including eventListeners As a variable inside of a method - you can create an array in line by using the variable block. This creates an array that will only be accessible within the method it is created. It can be passed as a parameter that is set up as an array of the same data type.

Arrays Creating an Array Select whether you want to the array to be a variable or a constant Check the is array box Enter a name for the array

Arrays Data Type Selection When selecting the data type for the array it is important to think about the type of data that can be put in the array. You should think about what information may be added later when considering the type. You might set it up only using bipeds but if you will be adding flyers or swimmers to it later you should select a higher class in the hierarchy such as sModel.

Arrays Initializing the Array When creating an array you will initialize the array by adding elements. An array can be any number of items including 1. The number of items you add to the array when setting it up will define the size of the array in Alice. You will not be able to add more elements to the array through code later.

Arrays Resulting Declaration The array declaration is now listed in the Scene Class. Fish[] indicates an array of Fish objects

Arrays Accessing an Array Access means to set or get an object or value. To access a specific object in an array you use the array name and select the correlating index. *using the random number function is a great way to grab a random item from an array

Arrays Changing Elements of a Variable Array The control block assign allows you to change the values inside an existing array. When referencing a single element of an array you will see the array name followed by a number that represents the location in the array.

Arrays Arrays in Control Structures When creating for each in __ and each in __ together control structures you will need an array to support the functionality of the structure. The program will either loop running once for each element in your array for each in__ or will process a do together for each element in your array each in__together.

Arrays Local Variable When selecting a name remember you are creating a variable that will hold each item of the array for use in the procedures. Name it something that helps you remember that it will be a placeholder for each item from the array. You will use this as a representative variable that will pass through each element of the array when programming the content of the control block.

Arrays Setting the Array You can make a new custom array for use locally or you can access an array you created elsewhere. If you don’t see the array you created remember that the class or method where you created the array matters for access.

Arrays Using the Element Variable The resulting structure shows the variable and the array. If the array is an object type you can access the variable as an object in the drop down and drag procedures into your control structure block that are populated with the array variable. If the array is a non-object data type you will need to create the appropriate statements and access the variable in the drop down or drag the variable into the appropriate parameter.

Arrays Arrays in Event Listeners Certain events can be modified with an add details to limit the listener using an array named setOfVisuals. Other types of events require the use of an array such collision listeners. The initializeEventListeners is a scene class method so recall that if you want to access existing arrays you will want to create them at the scene property level.

Arrays setOfVisuals Parameter Mouse click events are by default applied to all objects in the scene. To limit what objects are affected or will return data an an event you can use the set of visuals detail that will prompt you to create an array or you can make use of a scene class array giving you more flexibility (especially if it is a variable)

Arrays Position Orientation Arrays In Alice, the listeners for collision detection use two arrays The first array will contain all the objects in the scene that are moving and may possibly run into something else. The second array will contain all the objects in the scene that we do not want the moving objects to collide with. It is possible that these arrays may contain only one object