BASICS

Variables & conditions

Store information with variables, local variables, parameters and properties, and make decisions with conditions.

The video tutorial for this page is coming later. Subscribe to the RPG Paper Maker YouTube channel to see it as soon as it is out.

Even simple games need to remember things: was the chest opened, how far the quest went, how many coins the hero has. This page explains where to store information, and how to make decisions with it.

Where to store information#

RPG Paper Maker has four kinds of storage. They all hold a value, but differ in who can see them and how long they last.

KindWho can read and change itHow long it lasts
VariableEvery object, every map, every common reactionThe whole game (saved in save files)
Local variableOnly the reaction that created itUntil that reaction ends
ParameterThe event or common reaction it belongs toOne event or one call
PropertyOnly the object that has itAs long as the object exists (saved)

Value types#

A value can be:

  • a Number (positive, negative, decimal),
  • a Switch (ON or OFF),
  • a Text (a message).

Variables#

Variables are global: any object, map or common reaction can read and change them. They are saved with the game.

Open the Variables manager from the main toolbar (or from any variable field).

doc34.png

  • Variables are grouped in pages. Rename the pages (Story, Quests, Hero…) and keep similar variables together; leave free space in each page to add related variables later.
  • Always name your variables (Quest step, Coins found, Boss defeated…): your commands become much easier to read.
  • Default value: the value a variable has when a new game starts (a number, a switch or a text). Without one, a variable starts at 0.
  • Find usages lists every place where a variable is used: handy before renaming or reusing one.

Tip: writing some names in CAPITALS makes important variables stand out in long lists.

Change variables#

The Change variables command changes a variable, or a range of variables.

doc35.png

Selection: One variable, or a Range of variables (from … to) that all get the same change.

Operation:

  • Equals: replace the value. Works for every type.
  • Plus / Minus: add or subtract. Plus also adds text at the end of a text.
  • Times, Divided by, Modulo (the remainder of a division: 10 modulo 3 = 1). Numbers only.

Value: what to use in the operation:

  • Number (or the value of another variable, a parameter, a property…), Random (a number between two values), Text, Switch.
  • Number of an item, weapon or armor in inventory.
  • Total currency: how much of a currency is owned, earned (in total) or used (spent).
  • A statistic of a hero or enemy (Hero / Enemy instance ID, Statistic ID).
  • A characteristic of an object of the map (Object ID): its X, Y or Z position in squares or pixels, its Orientation (0 south, 1 west, 2 north, 3 east), the Terrain under it, or the value of one of its properties.
  • The instance ID of an Enemy of the current battle (in troop reactions).
  • Other characteristics: current map ID, number of heroes in the team, hidden or reserve, total steps, playing time in seconds, number of saves and battles, camera position, seconds played of the current music or background sound.
  • Value at position: the Terrain at a position, or the Object ID found at a position (in squares or pixels).
  • Script: the result of a JavaScript expression.

Floor result rounds the result down to a whole number.

Local variables#

Local variables live only inside the reaction that creates them, and disappear when it ends. Use them for temporary values (a counter in a loop, a random position, a calculation) instead of filling your variable list with "temp" variables.

Use the Change local variables command:

  • Create a new local variable with a name and a value.
  • Update an existing local variable of the reaction.

Local variables can be used in most command fields, like variables, and shown in texts.

Parameters#

Parameters are values given to an event or a common reaction each time it is used.

  • Event parameters are created in Systems manager > Events / States. The object sending the event chooses their values in the Send event command; the objects receiving it can read them. Example: a Sword attack event with a Power parameter.
  • Common reaction parameters are created with the common reaction. Call a common reaction sets their values.

Each parameter has a Default value. You can't change a parameter with a command, but its value can come from a variable or a property.

Properties#

Properties belong to one object: each copy of the object keeps its own value. They are created in the object's Properties list (name and initial value), and changed with the Modify property command, which can target another object of the map too.

Use them for anything specific to an object: a monster's HP, whether a character was already talked to, the age of a plant… Copy and paste such an object: each copy works on its own.

doc36.png

Conditions#

A Condition command runs commands only if something is true. Check Add else when conditions do not apply to also run other commands when it is false.

doc37.png

You can combine several checks with and / or.

Variables / Param / Prop#

Compare a variable, local variable, parameter or property with any value: equal to, not equal to, greater than (or equal to), lesser than (or equal to).

Heroes#

Check all the heroes, none of the heroes, at least one hero or the hero with instance ID, optionally only those in the team, reserve or hidden. Are they named something, in a group, able to use a skill, equipped with a weapon or armor, under effect of a status, or do they have a statistic value?

Possessions#

Compare how many of a currency, item, weapon or armor the player owns. For weapons and armors, you can count equipped ones too.

Others#

  • Key ID is pressed or not.
  • An object is looking at a direction, or is climbing.
  • A chronometer value.
  • The player escaped last battle.
  • Script: a JavaScript expression that returns true or false.

Using values instead of fixed numbers#

Most command fields can use a variable, a parameter or a property instead of a fixed value. Change the variable, and the command does something else.

Example: give the player a choice of which hero to heal. In each choice, set a Hero to heal variable to the hero's instance ID. Then a single Change a statistic command uses Hero to heal to heal the chosen hero.

You can also loop over things: set a variable to the first hero's ID, check that hero in a condition, add 1 to the variable, and repeat with a Loop until every hero was checked.

doc38.png

Start simple, and build up. Comments (the Comment command) help a lot when you come back to your commands months later.

Next: the full list of Event commands.