More ways to control program flow

In Week Four we are looking at some more advanced concepts for controlling what happens in our video game projects:   

Messaging:  A type of communication within code or between different software components or even across systems. The sending code broadcasts a message; the receiving code is listening for that message and reacts based on the requirements. Publish/Subscribe represents a well-known Software Design Pattern that is implemented in different ways in different programming languages. In Scratch it is implemented by:

  • a Broadcast Event; within the event declare a name for the message; example: Broadcast GameOver
  • a Receive Event that is listening for the specific message and executes a script when that message is heard; example: when I receive GameOver show the end game background and play the victory tune.

January 29, 2016 Meeting

Agenda:

  • Wireless connection announcements & Housekeeping
  • Discussion of our new project – Geneva Film Festival Website
    • Meeting with Geneva Film Festival representative
  • Demos of any of last week’s Scratch projects (In case anyone created something during the week that they want to share)
  • Continuation of GWC Lesson 1.2 – Video Game Lab
    • Use Scratch to create a video game
      • Your player should move with at least two arrows
        • BONUS FUN: Use the Makey Makey to move your player!!!
      • Your player should do something (sound, costume change, etc) when your player touches an object or canvas edge
      • Shapes can fly horizontally across the screen
      • Your player can catch flying objects
      • The background can move while the character moves so that some things look farther away
      • Make the world appear to continue to go forever by adding another platform
  • Questions/Comments/Discussion

Note: We will be meeting in the board room in 25N.

Silly Example of Scratch Data Lists

Last week, an obnoxiously long texting acronym made it’s way into our conversation. I was reminded how I really need to brush up on this sort of super important information. So I wrote a Scratch app that uses two data lists to allow me to look up an acronym from a list of ten. This example uses variables, data lists, user input and a cute little orange martian guy. I wonder what would happen if I enter one that isn’t on the list? Why don’t you try it and find out!

https://scratch.mit.edu/projects/95235421/

PAAT

Program Flow of Control

Our second and third weeks focus on flow of control within a program:

Algorithm: Logical step by step outline of the processes to be implemented to solve a problem. Includes decision points with branches defining what to do for each case. An algorithm is language-agnostic, i.e., it does not use syntax specific to a particular programming language. For all but the simplest programs, an algorithm is an essential part of the software development process

Flowchart: A diagram that is a graphical representation of a process. Each process step is represented by a rectangle; each decision is represented by a diamond with branches coming off for each choice. A flowchart may represent one part of a larger program, breaking it down into manageable components.

Scenario: Describes a particular set of events, data values, or user choices that direct a program to flow in a predicted direction. Each scenario will have an algorithm and possibly a flowchart to define what happens in that set of circumstances.

  • Use Case: A style of scenario definition that describes one specific way in which the users will interact with the software.
  • “Happy Day” Scenario: The user(s) and data behave in the way expected; no errors happen
  • Alternate Scenario: Something untoward may have happened; perhaps an error; or the user behaved unconventionally (submitted “bad” data, clicked buttons out of order….)

Flow of Control: the order in which the steps of a program are carried out as determined by control structures within a program. Control structures include loops, conditionals, function or procedure calls

  • Loop: a flow of control structure that causes code to be repeated a specified number of times or based on a condition (while or until some condition is true); a loop that runs “forever” is called an Endless Loop
  • Conditional: a flow of control structure that determines what code gets executed based on a decision. The conditional to be evaluated may use a combination of several Operators. For example: If (X > Y) Or (Y < 0) uses relational operators along with a logical operator. The exact syntax will vary with language. Order of evaluation is extremely important!
  • Operators:
    • Arithmetic: Addition, subtraction, multiplication, division, modulus (remainder after division); in Scratch these operators are represented by +, -, *, /, and mod
    • Logical: Not, And, Or, XOR (exclusive OR)
    • Relational: =, >, <,  >=, <=
    • Boolean: True or False. The conditional IF block will evaluate to a Boolean result
  • Event: a trigger that a program or component  is “listening” for so it can react
  • Stop or Start
  • Nested Control Structures: A control structure may have another control structure nested within it: nested IF’s, nested LOOPS, etc.  It’s a good idea to use a flow chart, or pseudo-code (plain English statements rather than programming syntax), or otherwise draw out or act out what will happen to make sure things go in the intended order

Variable: a named data element representing a piece of information to be remembered. A variable should have a meaningful name! In our video game we may want to define a variable named Score. The code may set the variable’s value based on some condition. For example: If the hero rescues the princess increase the Score by 1000;  if the hero falls into a fire pit decrease score by 50.

January 22, 2016 Meeting

Agenda:

  • Wireless connection announcements & Housekeeping
    • Discussion on 2016 Club Name?
  • Brief introductions for new students
  • Brief overview of Web site – let’s blog together!
  • Brief discussion of possible future projects
  • Demos of any of last week’s Scratch projects (In case anyone created something during the week that they want to share)
  • Conditionals in Scratch: PowerPoint, Worksheet, and Group Code
  • GWC Lesson 1.2 – Video Game Lab
    • Use Scratch to create a video game
      • Your player should move with at least two arrows
        • BONUS FUN: Use the Makey Makey to move your player!!!
      • Your player should do something (sound, costume change, etc) when your player touches an object or canvas edge
      • Shapes can fly horizontally across the screen
      • Your player can catch flying objects
      • The background can move while the character moves so that some things look farther away
      • Make the world appear to continue to go forever by adding another platform
  • Questions/Comments/Discussion

Note: We will be meeting in the board room in 25N.

About Face!

At our last meeting we had the question of whether we could set up our Sprites to face the direction of their movement automatically instead of having separate costumes for mirror images. It turns out that we can use the Rotation Style setting of each sprite to do that!

In this example, the characters will all start moving to the right and are programmed to make a 180 turn when touching the edge. How they look on their return trip to the left depends  on the Rotation Style setting.

Scratch Rotation Style
Scratch Rotation Style

Here they are after the 180; they are all moving to the left although one looks to be upside down and another moves “backward”:

ScratchRotationStyle2

Design Time vs Run Time Property Settings: Setting the Rotation Style in the IDE (Integrated Development Environment) as above is an example of a Design Time Property Setting. We can also change the Rotation Style during the program execution, i.e. Run Time,  by using the Set Rotation Style command in the Motion section of scripts. 

Hold That Tiger!

If you’ve spent millions of hours perfecting your artistic rendition of a new Sprite in Scratch’s costume editor, (let’s say an adorable tiger!) and another billion hours working out the complex script for the little guy’s dance moves, you may want to re-use the costume art and/or the script in the same project and you’ll definitely want to save them for posterity.

Here’s how to “leverage existing code” (programmers like to say stuff like that and managers LOVE to hear it!)

ScratchExample1
Code Re-Use is Essential to a Programmer!!!!!!!!

January 15, 2016 Meeting

Agenda:

  • Makey Makey Demo Learn More About Makey Makey
  • Wireless connection announcements & Housekeeping
    • Discussion on 2016 Club Name?
  • Brief introductions for new students
  • Demos of any of last week’s Scratch projects (In case anyone created something during the week that they want to share)
  • GWC Lesson 1.2 – Intro to Loops / Generative Art Lab
    • Loop powerpoint
    • Using Scratch to create loops / shapes
    • Loop worksheet
  • Questions/Comments/Discussion

Note: We will be meeting in the board room in 25N.

 

Intro to Programming and Scratch

In our first meeting we discussed a little history of computer programming and introduced Scratch:

Program: A set of computer code written to execute some useful feature, application, etc.

Programming Languages: A defined set of instructions that can be used to tell a computer what to do. Programmers write code by determining which instructions to put together in which order

  • Machine Language: Set of instructions composed of numerical “bits”, only ones or zeroes. A computer understands this natively, each processor family has its own set of instructions. They would look something like this: 00100001 11101011 01010101
  • Assembly Language: Also called Assembler Language. Low-level programming language; uses abbreviated words (Mnemonics), e.g. MOV, to represent instructions to the computer. Assembly instructions are translated by the Assembler into machine language
  • High Level Language: Each language has its own syntax, keywords, functions, etc. Uses natural language, such as English. Abstraction refers to the way in which these languages abstract details of what the machine needs to be told, so that a simple function call can actually represent many instructions behind the scenes

Compiler: Translates high-level languages to code that can be executed by the computer.  There are specific compilers for each language (Java, C#, COBOL, etc.). Compilers do a lot of the complex work behind the scenes of a program. Note: Some languages are Interpreted rather than Compiled; that is, the code is executed as it is being read

Debug: Figure out what is wrong with a computer program and fix it.  Specialized debugging tools are often part of a development environment and allow programmers to step through the code one line or block at a time and inspect the immediate results

IDE: Integrated Development Environment. An application that provides an interface and tools for programmers to create, execute, and debug code. Visual Studio, Scratch, Eclipse, NetBeans are all examples of powerful IDE’s

Loop: a code control structure that causes code to be repeated a specified number of times or based on a condition (while or until some condition is true); a loop that runs “forever” is called an Endless Loop

Event: a trigger that the program is “listening” for; code blocks can be “hooked” to events so they will execute when the event occurs. In Scratch, an event commonly used at the top of a script is the clicking of the green flag to start

Script: A set of computer instructions connected to run together to do something. In Scratch, we create scripts by connecting blocks

Scratch: a visual programming language developed at MIT enabling coders to drag and drop blocks of code to form scripts to control sprites on a “stage”

  • Sprite: an image, often like a cartoon character, to which scripts, costumes, and sounds can be attached to control its appearance, movement, and behavior
  • Backdrop: the scenery behind the Sprites within a Scratch project
  • Stage: the area on which the backdrops and sprites are drawn and move
  • X/Y Coordinates: define a point on the stage. X represents the point on the horizontal axis from -240 on the far left to +240 on the far right. Y represents the point on the vertical axis from +180 at the top to -180 at the bottom. The center of the stage is at 0,0.
  • Block: In Scratch, a block is a unit of code that can be added to a script to build a working program

January 8, 2016 Inaugural Meeting

Tonight, the inaugural meeting of the Fox Valley Girls Coding Club was held at 25N Coworking in Geneva, IL.  Participants and teachers went through brief introductions before we started working with Scratch (scratch.mit.edu), a web-based graphical programming tool that quickly and easily allows for the creation of interactive stories, games and animations. We are following the curriculum created by the non-profit organization, GirlsWhoCode (girlswhocode.com).