Chapter 16 – Programming your App’s Memory

Slides:



Advertisements
Similar presentations
Introduction to Macromedia Director 8.5 – Lingo
Advertisements

Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Understanding an Apps Architecture ASFA Computer Science: Principles Fall 2013.
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
App Inventor Useful links:
靜宜大學資管系 楊子青 1 Programming Your App’s Memory 靜宜大學資管系 楊子青
App Inventor Barb Ericson July 3, 2013.
The Creative Art of Programming © Copyright 2014 Barbara Ann Walters. All Rights Reserved.
Ch 14. Understanding an App’s Architecture Two perspectives 1.Programmer: a)Components & Behaviour b)Designed in Component designer Blocks editor 2.End-user:
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Creating Mobile Apps with App Inventor! Day 5 Google search Kris Gordon Ludlow for links.
Quadratic Equation Solver Tutorial. Introduction We will be making an app to solve 2 nd level polynomials like ax 2 +bx+c. We will model our app upon.
Chapter 7 Designing Classes. Class Design When we are developing a piece of software, we want to design the software We don’t want to just sit down and.
A First Program Using C#
11 Games and Content Session 4.1. Session Overview  Show how games are made up of program code and content  Find out about the content management system.
Copyright ©: SAMSUNG & Samsung Hope for Youth. All rights reserved Tutorials Software: Building apps Suitable for: Advanced.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
App Inventor MIT App Inventor.
Variables, operators, canvas, and multimedia Dr. José M. Reyes Álamo.
Introduction to programming in the Java programming language.
Making Python Pretty!. How to Use This Presentation… Download a copy of this presentation to your ‘Computing’ folder. Follow the code examples, and put.
Game Maker – Getting Started What is Game Maker?.
Variables, operators, canvas, and multimedia Dr. José M. Reyes Álamo.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
Lesson 1 – Getting Started with App Inventor
Input, Variables, and Calculations. The TextBox Component Performing Calculations Storing Data with Variables Creating Blocks with Typeblocking The Slider.
Introduction to Programming and App Inventor. Introduction What is a computer program? Introducing App Inventor Getting hands on with App Inventor.
JavaScript Part 1 Introduction to scripting The ‘alert’ function.
Object-Orientated Programming
Concepts of Object Oriented Programming
Scratch for Interactivity
PYGAME.
Chapter 1: An Introduction to Visual Basic 2015
Chapter Topics 15.1 Graphical User Interfaces
Chapter 8: Writing Graphical User Interfaces
Visual Programming week # 02 APP (Application) Architecture.
Engineering and Debugging an App Chapter 15
Understanding an App’s Architecture
Visual programming Chapter 1: Introduction
Using Procedures and Exception Handling
Introduction to Events
Programming Your App to Make Decisions – Conditional Blocks
Chapter 2 Visual Basic Interface
Introduction to Object-Oriented Programming
Understanding an App’s Architecture
Lesson 4: Controlling Memory with Variables
Number and String Operations
Visual Basic Programming Chapter Four Notes Working with Variables, Constants, Data Types, and Expressions GROUPBOX CONTROL The _____________________________________.
HAPPY NEW YEAR! Lesson 7: If-statements unplugged
Items, Group Boxes, Check Boxes & Radio Buttons
Lecture Set 11 Creating and Using Classes
Game Loop Update & Draw.
An intro to programming concepts with Scratch
Introduction to AppInventor
ICT Gaming Lesson 3.
Chapter 15: GUI Applications & Event-Driven Programming
Using screens and adding two numbers - addda.cbl
Programming Lists of Data 靜宜大學資管系 楊子青
Tonga Institute of Higher Education IT 141: Information Systems
Chapter 8 - Functions and Functionality
Tonga Institute of Higher Education IT 141: Information Systems
Chapter 7 Event-Driven Pages
CS334: Logisim program lab6
CAMP 1 – MODULE 3 INSIDE MATHEMATICS
Presentation transcript:

Chapter 16 – Programming your App’s Memory App Inventor 2

Chapter 16 - Introduction Just as people need to remember things, so do apps. This chapter examines how you can program an app to remember information. When someone tells you the phone number of a pizza place, your brain stores it in a memory slot. If someone calls out some numbers for you to add, you store the numbers and intermediate results in a memory slot. In such cases, you are not fully conscious of how your brain stores information or recalls it. An app has a memory as well, but its inner workings are far less mysterious than those of your brain. In this chapter, you’ll learn how to set up an app’s memory, how to store information in it, and how to retrieve that information at a later time.

Named Memory Slots Some are created when you drag components onto Designer Properties of components are themselves named memory slots as in: btnSubmit.Text = “Click Here to Submit” Some are created independently of components. These are called ‘variables’. Think of these as the app’s hidden ‘scratch’ memory

Properties Set values for these directly in the Component Designer Properties can have various types. Look at example (Canvas1 component): ‘BackgroundImage’ type is a PNG file ‘BackgroundColor’ and ‘PaintColor’ are colors ‘Visible’ type is Boolean ‘Width’ and ‘Height’ are numeric or a special designation (Fill Parent…)

Properties Setting properties in Component Designer ‘initializes’ them These are the values the component properties will have when the app starts They can change during execution (as the app runs). This is handled by the Blocks. When the app runs you no longer see the Component Designer, so you no longer see the property values in the running app

Defining Variables These are named memory slots, just like properties, but they are not associated with components. Example: Game app might need to track what ‘level’ a player has reached Could be stored in the ‘Text’ property of a Label If it’s not something that needs screen space, use a variable instead President’s Quiz (Ch8) uses variables to store a list of questions (only one question is visible at a time, so where are the others stored?).

Three steps to creating/initializing a variable Drag the initialize global variable  from the Variables drawer in the Built-In blocks Change the name of the variable by clicking on the text “variable” and typing “score” Set the initial value of the variable by dragging out a number block from the Math drawer and plugging it into the variable definition.

Remember . . . When you define a variable, you tell the app to set up a named memory slot for storing a value. These memory slots, as with properties, are NOT visible to the user as the app runs. You can also initialize the variable with a make a list or create empty list block. This sets the app up to work with lists of values which we explore in Chapter 19.

Setting and Getting a variable’s values There are two built-in blocks for this:

Examples of ‘set’ting and ‘get’ting values in variables

New in AI2!!! Scoping of variables You can create ‘global’ variables (this is not what’s new) This means that the named memory slot is visible and available from all parts of the app You can now also create ‘local’ variables This means that the named memory slot is only visible and available to selected parts of the program Local ‘scoping’ of variables is an extremely important new feature in AI2 and allows for the possibility of supporting larger-scale collaborative software projects

Setting a variable to an expression ‘Expression’ is a computer science term for ‘formula’ Say you need to change a ‘score’ variable to 5 more than what it’s current value is (what behavior might cause this to happen?) You would need an expression similar to the following score = score + 5 (is there a problem with this?) The way you ‘say’ this in App Inventor follows:

How blocks are processed Processing is done ‘inside-out’ First block: get (global score) Second block: ‘5’ Third block: ‘+’ Fourth block: set (global score)

How blocks are processed If 10 was already in here … And we take the value ‘5’ … And add it to the 10 … We then take the result (15) and put it back in here …

Building Complex Expressions Math drawer has lots of tools

Building Complex Expressions Use the math blocks to build expressions like this: What does the set of blocks above actually do?

Displaying Variables One advantage of storing data in a variable as opposed to a component property: it allows you to show just the data you want when you want to show it Allows you to separate the computational part of your app from the user interface – an important software engineering principle! Manageability of code: see discussion in last two paragraphs under heading ‘Displaying Variables’ in the chapter.

Local Variables ‘Global’ variables have access to all event-handlers and procedures in the entire app. Sometimes this is good – on larger projects, this can be a DISASTER. Makes collaboration really difficult. App Inventor now allows ‘local’ scoping: If the variable is only needed in one place, it is a good idea to define it as a local instead of a global. By doing so, you limit the dependencies in your app and ensure that you won’t mistakenly modify a variable. Think of a local variable like the private memory in your brain--you certainly don’t want other brains to have access to it!

Summary When an app is launched, it begins executing its operations and responding to events that occur. When responding to events, the app sometimes needs to remember things. For a game, this might be each player’s score or the direction in which an object is moving. Your app remembers things within component properties, but when you need additional memory slots not associated with a component, you can define variables. You can store values into a variable and retrieve the current value, just like you do with properties. As with property values, variable values are not visible to the end user. If you want the end user to see the information stored in a variable, you add blocks that display that information in a label or another user interface component.