GameSalad Academy

Unit 5 Top-Notch Trivia: Mac

29 STUDENTS ENROLLED

UNIT 5: TOP-NOTCH TRIVIA (MAC VERSION)

“Top-Notch Trivia” is the fifth unit in the GameSalad game design curriculum series.  It introduces concepts of conditional branching and multidimensional arrays (GameSalad’s table feature) in a quiz game that inspires creativity.

COMPUTER SCIENCE CONCEPTS:

Data Structures: In GameSalad, you’ve worked with attributes, which are single pieces of data. But sometimes, you need a way to organize many pieces of data. This grouping of data is called a “data structure”. Data structures are ways to organize large amounts of data in your program so that you can easily access and process it.

In GameSalad, data that is not stored in attributes is stored in a structure called a table. Tables let you store lots of data in one place, and easily access it through different means.

Arrays: In programming, one of the most basic data structures is an Array. Any array is a list of objects that are all the same type. You can look up any piece of data in an array by its number position. A single column in a GameSalad Table is just like an array. Each column can only be one type (“Text”, “Boolean”, “Integer”, “Real”, etc) and you have lots of bits of data stored in order.

Depending on what programming language you are using, the starting number of an array will be different. Most languages will start counting the items in an array with the number ‘0’. So in this array:

[8,1,3,4,5,6]

To get the first item, you’d ask for item ‘0’ and get ‘8’.
To get the third item, you’d ask for the item ‘2’ and get ‘3’.

In GameSalad, we start at the number ‘1’.

To get the first item, you’d ask for item ‘1’ and get ‘8’.
To get the forth item, you’d ask for item ‘4’ and get ‘4’.

You can also store arrays in arrays! So if each column in a GameSalad Table is an Array, a Table in GameSalad is an Array of Arrays!
To get data from GameSalad Tables like you would from an array, you use the tableCellValue function.

Data Driven Programming: Most of the time, when you’re programming, you’re giving a computer a list of instructions to follow. But if the list of instructions is very long and are all very similar, it can be tedious to write the code (or drag in the behaviors) for every instruction inside your program!
Any time you want to change what your program does, you would have to change the program.

You could, instead, write a program that reads data from a data structure, and use that data structure to decide what to do next. This way, you don’t have to change your program, you just change the data the program reads. This is called Data Driven programming.

GameSalad games are themselves Data-Driven programs. Instead of being driven by an array or similar data structure, its behavior is driven by your input and time.

Strings and String Comparison: When making games in GameSalad, you’ll often type words and sentences into attributes or table cells. These words and sentences are called Strings. Strings are objects that represent a list of characters. We explained earlier that an Array as a list of the same type of data. Behind of the scenes in most programming languages, a String is really an Array of characters.

Computers work with numbers. When you type something into a computer, you see a character like ‘A’, but the computer sees a number. Each character is represented by a number. To a computer a string is an array of numbers.

A computer will see the string “HELLO” as an array of the numbers [72, 69, 76, 76, 79].

You can do things like add strings together (in GameSalad you do that by using the .. operator in a expression).

You can check if one string is like another string (with “Text Expression” or “String Expression” Rules).

Checking whether a string is like another string is called “String Comparison”. Every time your program tries to check whether one string is like another, it’s really comparing each string one character at a time. So the longer the strings you are comparing, the longer the computer will take. Luckily, checking each character is very fast.

Instance / Local Variables: In programming, variables (in GameSalad we call them attributes) can have different scopes. A scope is part of the program where you can access and change a variable.

Most programming languages have a concept of a “global” variable, which is a variable you can see anywhere in the program. In GameSalad, game attributes are like global variables. You can see them from any actor in GameSalad, and any actor can change them.

In GameSalad you can also have scene and actor attributes.

The scope of a scene attribute is only actors in a given scene. So if your actor is in one scene, it’s behaviors can’t see or change the scene attributes of another scene.

The scope of an actor attribute is only the actor itself. Only behaviors inside the actor can see or edit that actor’s attributes.
Programmers use scope to help them better organize their code.
Let’s say you have a secret health attribute for each of your actors. After you build your game you realize there’s a bug where the secret health attribute is being set to the wrong value!

If you put that secret health attribute into a game attribute (a global variable), you would have to check every actor in your game to find the one that’s setting the wrong value.
Instead, if you made the health an actor attribute, then you would only need to check one actor, since only one actor could change this secret attribute!

 

GameSalad™

Game Development Curriculum

Danielle Burnett, Principal Learning Architect, GameSalad, Inc. Version 2.0 • March 2016

PRIVATE COURSE
  • PRIVATE
  • 365 Days
Skip to toolbar