Variables hold what a mode needs to remember between events: a score, who's "it", which wave it is. This guide covers the kinds of variables, the containers (structs, enums, arrays, maps and data tables), and the Saved nodes that keep values after the map ends.
Make a variable
- In My mode (left), press + by Variables and name it.
- In Details, pick its Type (number, yes/no, text, vector, color, transform, player, team, a weapon, a file, an enum, a struct, an array or a map: see Types and casting), One for, Kept and Starts at.
- Drag it onto the graph: you get Get Variable or Set Variable.
Add To Variable adds to a number and Toggle Variable flips a yes/no. A mode has up to 64 variables.
Mode, player and team variables
One for says how many copies there are:
| One for | What it means | Use it for |
|---|---|---|
| The whole mode | One value for the server. | The wave number, the current "it", a round counter. |
| Each player | Every player has their own. Get and Set need a Player wired in. It starts again when they join. | Lives left, a kill streak, a chosen class. |
| Each team | One per team. Get and Set need a Team. | Team points, a team's upgrade level. |
Kept says when it starts over: For the map, or Starts again each round. A round variable is the easy way to get a "this round only" count without resetting it yourself.
To count each player's kills this round and reward the third:
Player Killed → Add To Variable (Kills, Attacker, 1) → Branch (Compare: Get Variable Kills = 3) → True → Give Weapon (Attacker, awp)
with Kills set to One for: Each player, Kept: Starts again each round.
Variables hosts can change
A whole-mode number or yes/no variable can be a Setting (hosts can change it). Hosts then set its start value on the Play page, the server page and the in-game admin menu, without editing or compiling the mode. Give it a label, help, a range and a group. The comfort limits are settings like this, in the Limits group.
While you Playtest, Live values › Change sets a variable in the running game at once, and Use as start value copies it back into your graph.
Structs and enums
An enum is a list of named choices: scout, tank, medic. A variable of that enum can only hold one of them. Enum Value picks one, Switch on Enum goes to the output for the value, Enum To Number gives its number (from 0).
A struct groups values under one name: a loadout with a primary, a secondary and armor. Make Struct builds one, Break Struct splits it into its fields, Set Field changes one field of a struct variable.
Each field holds one value: a number, yes/no, text, a vector, a color, a file (model, sprite, sound or decal), a player, an entity or an entity handle (NPC, creature, projectile...), a team, a timer, a sound loop or an enum. A field can't be an array, a map or another struct: for a list, make an Array of the struct instead (a list of loadouts).
Player Spawned → Switch on Enum (Get Variable Class, Player) → Tank → Set Health (Player, 200)
Arrays
An array is a list of values of one type (up to 10000 items). Make an array variable, or get one from a node such as Players Array, Players In Radius, Find Entities or Split Text.
- Change it: Add, Insert, Remove Item, Remove Index, Set Array Item, Clear, Shuffle, Sort.
- Read it: Get (from 0), Length, Contains, Find, Random Item, Sum.
- Go through it: For Each.
To keep a queue of players waiting to play:
Player Joined → Add (Queue, Player)
Player Left → Remove Item (Queue, Player)
Maps
A map (the container, not a game map) looks values up by a key: a text, a number or a player. A map<player, number> is a score per player that you can list.
- Map Add puts a value under a key (replacing what was there); Map Remove and Map Clear take them out.
- Map Find gives the value and Found; Map Contains, Map Length, Map Keys and Map Values read it.
Arrays, maps and structs are always one for the whole mode.
Data tables
A data table is a grid you fill in (My mode › Data tables), or paste from a spreadsheet: a gun list, prices, waves. Each column has a type and the key column names each row. It's built into the plugin, so reading it costs almost nothing, but the mode can't change it while it runs.
- Get Row: the row with this key, every cell as a pin.
- Get Cell: one cell by row number (from 0).
- For Each Row, Find Rows, Row Count, Row Keys.
A column can also hold a weapon, an entity name, or a model, sprite or sound (a loot table with a model per row). A mode can have 16 tables of up to 16 columns and 256 rows.
Player Killed → Add To Variable (Level, Attacker, 1) → Get Cell (Guns, Weapon, Row: Level) → Give Weapon (Attacker, Value)
Saved values
Variables last for the map at most. To keep something longer, use the Saved nodes. They keep values across map changes, server restarts and crashes, in the mode's own file:
- Saved Value and Save Value: a number for each player (wins, XP, coins). Add To Saved adds to it.
- Saved Text and Save Text: text for each player (a title, a chosen skin), up to 63 letters.
- Server Value and Set Server Value: a number and a text for the whole server (a record time and who set it).
- Top Players: the best players by a saved value, offline players too, one place at a time. How many places is the Top Players places setting (10 to start).
Players are known by their Steam ID; bots and LAN players by their name. The file is written within 5 seconds of a change and at the map's end, and a crash still leaves one whole file.
A win counter with a leaderboard:
Round Ended → For Each Player (Team: Winner) → Each → Add To Saved ("wins", Player, 1)
Chat Command ("top") → Top Players ("wins") → Each → Chat Message (Player, Format Text: "[0]. [1]: [2] wins")
Top Players reads the whole save file each time, so run it now and then (a round's start, a chat command), never every tick. The starter library's Leaderboard Display shows it in an info window.
What survives what
| New round | Map change | Server restart | |
|---|---|---|---|
| Variable, Kept: Starts again each round | Starts over | Starts over | Starts over |
| Variable, Kept: For the map | Kept | Starts over | Starts over |
| Player variable | As above, and it also starts over when that player leaves and joins again | ||
| Cooldowns (Start Cooldown) | Kept | Start clean | Start clean |
| Saved Value, Saved Text, Server Value | Kept | Kept | Kept |
| Data tables | Part of the mode: only change when you edit and install it again | ||
See also
- Events and flow: loops over arrays and players.
- Types and casting: the types a variable can hold.
- Variables, Arrays, Maps, Data tables and Saved in the reference.
- Variables, functions and macros and Data tables in the docs.