Computer science concepts in GameSalad
A teacher’s map from computer science concepts to GameSalad features: variables, data structures, conditionals, loops, functions, and object-oriented design.
Teachers often ask how computer science concepts map to GameSalad features.
Our tutorials introduce these concepts along the way, but you may not have time to work through every tutorial — or your class may skip the tutorial that covers a specific concept. This guide gives you a quick reference for how core CS concepts work in GameSalad.
- Summary sections assume familiarity with the concept and map it directly to its GameSalad equivalent.
- Detail sections provide background for readers less familiar with the concept — or anyone curious about what happens under the hood in GameSalad.
We refine this guide regularly, so if anything is unclear, feel free to reach out and ask.
See also standards alignment and the GameSalad curriculum.
Variables
Attributes
Summary: In GameSalad, variables are called Attributes.
Detail: A variable is a named label in code representing a spot in memory that holds data (or points to data elsewhere in memory). It's called a variable because the stored value can change while the label stays the same.
In object-oriented programming, variables attached to an object are often called members, properties, or attributes. Because everything in GameSalad is an object (including the Game itself), GameSalad calls all variables Attributes.
Types
Summary: GameSalad supports common programming types plus a few GameSalad-specific ones. text Attributes are strings, and real Attributes are floating-point numbers. angle and index are mostly documentation hints to signal a value's intended purpose.
Detail: Defining a variable usually requires two things: a name (the label) and a type (whether it holds a number, text, etc.). Types matter because computers store everything in binary (1s and 0s) and need to know whether those bits represent an integer, a floating-point number, or text.
Attribute types in GameSalad include:
- boolean: a value that is either
trueorfalse. - text: a string of characters (called a string in most programming languages).
- integer: a positive or negative whole number with no decimal places.
- real: a number with decimal places (called a float or floating-point number in other languages).
Two additional types are specific to GameSalad and mainly signal intent to anyone reading the project (older versions of GameSalad also used them to show specialized UI):
- angle: represents a real number between 0 and 360 degrees. GameSalad accepts any real number here, so the type primarily communicates that the value represents an angle.
- index: represents a positive integer greater than 0. GameSalad accepts any integer here, and the type indicates the value is meant to index into another structure (such as a Table). Because GameSalad's underlying Lua engine uses 1-based indexing, indexes start at 1 rather than 0.
Variable Assignment
Summary: Variable assignment uses the Change Attribute Action or the Constrain Attribute Behavior.
Detail: Attributes can be updated by system events — such as game.Time (updated automatically in seconds) or an Actor's x and y positions while moving — or by your own logic using Change Attribute or Constrain Attribute.
- Change Attribute updates the target Attribute once per trigger. At the root of an Actor's Behavior list, it runs once when the Actor is created. Inside a Rule, it runs each time the Rule's conditions switch to true.
- Constrain Attribute runs continuously while active, keeping one Attribute synced to another value or expression. Whenever the source value changes, the constrained Attribute updates too — useful for mirroring values between Actors.
Variable Scope
Summary: Game Attributes act like global variables; Actor Attributes act like local variables.
Detail: In early programs, every part of the code could access every variable, which often caused unexpected bugs when different sections overwrote the same data. Modern languages solve this with variable scope, limiting where a variable can be read or changed. While GameSalad doesn't have arbitrary block-level scopes, its Attribute levels serve a similar role:
- Game Attributes act like global variables — readable and writable by any Actor in the Game.
- Actor Attributes act like local variables — accessible only from logic inside that Actor Instance.
Data Structures
Summary: GameSalad lets you organize data in two ways:
- Actor Attributes — similar to structs or objects.
- Tables — similar to database tables with typed columns and numbered rows, read via Table functions. A single-column Table acts like an array; a multi-column Table acts like a multidimensional array or an array of objects.
Detail: While students naturally pick up Actor Attributes as they build, Tables are one of GameSalad's most powerful features.
In computer science, data structures are standard ways of organizing collections of data so they're easy to reason about and process with algorithms (searching, sorting, and transforming data).
GameSalad Tables are 2D structures made of rows and typed columns, much like database tables. You can use them to model several classic data structures:
- Arrays are the most basic data structure: a list of items of the same type stored contiguously in memory. A single column in a GameSalad Table works as (and is implemented as) an array. Items are accessed by index. While most languages start indexing at 0, GameSalad uses Lua under the hood, so indexes start at 1. Because every item has the same type and size, the CPU can jump straight to any index with simple arithmetic.
- Dictionaries (Maps / Associative Arrays) map keys to values — like words (keys) and definitions (values) in a real dictionary. While implemented differently under the hood, you can think of an array as a dictionary whose keys are integers. Arrays offer instant arithmetic lookup, while dictionaries search by key using specialized structures for fast, memory-efficient lookup. In GameSalad, every Table includes a special label column and row that can act as dictionary keys pointing to values in the data columns.
Compound data structures: Combining rows, columns, and labels lets a multi-column Table represent:
- An array of arrays
- An array of dictionaries
- A dictionary mapping keys to arrays
- A dictionary of dictionaries (row labels pointing to columns, with column labels pointing to values)
Conditional Statements
Rules
Summary: GameSalad Rules work like IF / THEN / ELSE (or WHEN / DO / OTHERWISE) conditional statements.
Detail: Most programming languages use if / then / else statements to control program flow. While it's easy to introduce GameSalad Rules as IF / THEN / ELSE, it's often clearer when debugging to think of them as WHEN / DO / OTHERWISE: when the conditions become true, do these Behaviors; otherwise, do something else.
Because Rules are evaluated continuously, they work as follows: whenever an Attribute referenced in a Rule's conditions changes, GameSalad re-evaluates the Rule. If the overall result changes to true, instant Actions inside the Rule run once and continuous Behaviors activate. When it changes to false, continuous Behaviors deactivate. If it becomes true again later, Actions run again and Behaviors reactivate.
Conditions
Summary: Conditions evaluate to true or false. Setting a Rule to Any combines conditions with OR; setting it to All combines them with AND.
Detail: While text-based languages allow nested boolean expressions, GameSalad keeps Rules simple with two modes:
- All: the Rule activates only when every condition is true (equivalent to
AND/&&). - Any: the Rule activates when at least one condition is true (equivalent to
OR/||).
Loops
Summary: Loop Over Table is an iterator (for-each) loop that runs once for each cell in a Table row or column. Loop is a while loop that repeats its Actions while a condition stays true. Loops should contain only instant Actions, not continuous Behaviors. GameSalad doesn't explicitly support nested loops, though they can be simulated with careful logic.
Detail: Loops let computers do what they do best: repeat a task automatically. GameSalad provides two loop Behaviors:
- Loop is a conditional loop (like a
whileloop in text-based languages) that runs while a set of conditions remains true. Typically, you update a counter Attribute on each iteration — for example, starting at 0 and adding 1 each pass until it reaches 10 (or counting down from 10 to 0). In theory, a loop can run indefinitely: sometimes that's intentional (like an OS or game-engine event loop), and sometimes it's a bug that stalls the program. - Loop Over Table is an iterator (
for-eachloop) that runs once for every value in a Table row or column. This is ideal when you don't know a Table's size ahead of time or want to guarantee you never read past the end of the data.
GameSalad loops and Max loops / frame
Unlike most programming languages, GameSalad loops include a Max loops / frame setting because every loop runs inside the game engine's own main loop. Up to 60 times per second, GameSalad:
- Updates Attributes linked to the system or hardware input
- Updates Actor positions via the Box2D physics engine
- Evaluates Rule conditions
- Runs newly triggered Actions
- Runs active continuous Behaviors
- Renders the updated frame to the screen
If a loop takes longer than 1/60 of a second, it delays the next frame and causes the game to stutter. Max loops / frame lets you balance speed and smoothness: raise it for lightweight loops so more iterations finish per frame, or lower it for heavy loops so each frame stays within 1/60 of a second.
Functions
Summary: GameSalad doesn't let you define custom functions directly, but you can simulate them with Actors using a Function Object (or Command Object) pattern.
Detail: Functions encapsulate logic into small, reusable chunks. A well-written function:
- Breaks complex code into smaller, easier-to-reason-about pieces
- Lets you reuse common instructions across a project
- Avoids unintended side effects by working only with the data it needs
While students use built-in functions inside expressions just like in text-based languages, GameSalad doesn't have custom function definitions. Instead, students can simulate a function using a Function Object (or Command Object) — an Actor containing only Actions or Loops:
- Copy any input arguments from Game Attributes into Actor Attributes using Change Attribute (freeing the Game Attributes for other calls).
- Run the desired logic with Actions or Loops.
- Store the result in an output Game Attribute or Table row.
- Destroy the Actor.
To "call" the function, simply spawn the Actor: it runs its logic, saves the result, and cleans itself up. Because Actions run in top-to-bottom order, this also lets students break complex calculations into clear, sequential Change Attribute steps.
Object-Oriented Programming
Summary: In GameSalad, the Game, Scenes, and Actors are objects, and Attributes are their properties (members/fields). Actors are the only programmable objects, effectively having one Behavior list. GameSalad uses prototypical inheritance: Actors in the Library are Prototypes, and copies dragged into a Scene are Instances that inherit the Prototype's Behaviors unless unlocked and overridden. There is no super or base keyword to call parent Behaviors once overridden.
Detail: Object-Oriented (OO) Programming organizes code into objects that combine data (properties/attributes) and behavior (methods). Objects can represent visible game elements, group related logic, or define shared behavior across many items.
GameSalad works with four object types:
- The Game
- Scenes
- Actor Prototypes (defined in the Library)
- Actor Instances (copies placed in a Scene)
In OO terms, a class (or prototype) is the blueprint in code, and an instance is a live copy in memory at runtime. While classic classes and prototypes differ under the hood, you can treat a GameSalad Prototype as synonymous with a class.
When you create an Actor in the GameSalad Library, you're defining a Prototype. Dragging it into a Scene creates an Instance that inherits the Prototype's Behaviors and default Attributes — unless you unlock the Instance. Unlocking copies the Prototype's Behaviors onto that specific Instance, breaking the link so later edits to the Prototype no longer affect it.
Classroom tip: If a student edits an Actor in the Library and wonders why their changes aren't showing up in the Scene, check whether that Scene Instance has been unlocked.
See these concepts in your classroom
Book a demo of GameSalad for Education, or get pricing for your school.
Schedule a demoLast updated