What is The Register

The register is a global database where the engine stores anything you want to use later. If global.register does not exist when the engine launches, it will be created automatically.

Where to modify

You can add or modify data in the register any time a choice is activated:

  • Each choice in the Choices tab has an option to modify the register.
  • Data may also be set within the conditions area of the Choices tab.

How to modify

To set a value in the register, you'll use the following form of expression:

r[variableName]=value

Suppose, for example, that the player is asked to choose from a selection of Fruits, and I wish to store the resulting choice. On the button for Apples, I might choose to set the register like this:

r[fruit]=apple

Later on, I'll be able to check the value of fruit, or even draw it, like this:

Ahhh, I see that you chose to take the [r=fruit]...

See the section on special text tags for details about modifying text with custom tags.

You can also modify values in the register, using the common programming notation of += and -=:

r[myGold]+=100
r[myGold]-=100

The code examples above will look for a stored value called myGold, and will attempt to increase or decrease it by 100.

r[myFruit]+=, and oranges
r[myFruit]-=apple
r[myFruit]-=*apple
r[myFruit]-=4

Text is a bit tricky, but the above code examples will look for a stored value called myFruit, and will attempt the following:

  • add words onto the end
  • remove the first instance of this text from myFruit
  • remove all instances of this text from myFruit
  • delete this number of characters from the end of myFruit

Saving and Loading the Register / Game

When a player activates any command that changes a value in the register, the register automatically saves itself. The saved register can be found in the %localappdata% folder of the player's computer, where all game data should be stored. Please have a look at GameMaker's article on The Sandbox, and file functions to get a better sense of where and how files get saved in Game Maker.

If you're going to modify the register in a way that is not through this engine, there's a convenient pair of functions: slidge_save_register(filename) and slidge_load_register(filename). By default, the engine will save the Register to a filename that is defined in the create_common_data() script. Use that name in your own function calls, if you want to save the register to the same location.

Once the register is loaded, there's additional tricks you can do, including saving and loading conversation progress. These additional features are covered below, in Data outside the engine

Conditionals

The conditionals system is somewhat complex, and can cause some remarkable interactions. The conditionals editor is launched in the following ways:

  • When you set a register value on a Choice
  • When you choose the Show If button on a Choice
Method Behavior
Register Button Prompts developer for a command, then launches the conditional editor with 1 command and no conditions
Show If Button Launches the conditional editor with 1 condition (IF True=True) and no commands

The Show If button exhibits a special behavior after evaluating the conditionals: the associated Choice button is shown or hidden depending upon whether the conditionals evaluated True.


In the image above, you can see that when activated, the engine will check if fruit = apple and if foundRuby = true. If both are true, it will change the value of endAction to caveOfWonders. This kind of feature can be immensely powerful; when the player clicks on a choice in your game, that choice could check multiple things, and change variables that are used later in the engine. And since you can set the link actions to be a variable, you can actually create choices that alter the behavior of choices and scenes in the future.

IMPORTANT Tips on using the conditionals editor

  • By default, there's no condition when you set a Choice Button's register. There's only a command. Click the +IF button to add a condition which will determine whether the command is executed.
  • By default, there's only a condition and no command when you set a Choice Button's “Show If” statement. You can subtract portions of the condition by clicking the -IF button. If you want to add a command, hold the Control key and you'll see a +DO button appear. To remove a command, click the command's text and delete everything from the box.

The conditionals editor is complicated and tricky at first, but once you use the interface a few times, it becomes a very fast way to apply complex logic.

A final note about evaluation order

The engine does a somewhat peculiar but useful form of evaluation. Consider the following:

In the conditional above, the register value of “secret” will be set to “True” if money is greater than zero AND Ruby is True.
Additionally, however, the value of “vendor” will be set to True if money >0, regardless of the value of Ruby.

In other words, each time a condition line evaluates to True, and DO command beneath it will execute, then the conditional evaluations will continue.

Data outside the engine

The register is a ds_map, and it is necessary to be familiar with this type of data structure before using it outside of the engine. Game Maker's page on ds_maps Has an overview of this type of data.

As your player goes through your game, the Register tracks several useful special values, which can be accessed by the rest of your game:

  • markedName : This is the name of a character who is “marked” in the Characters tab of your scene. This provides a quick and easy way to use SLIDGE to signal to your game that a certain character is doing something.
  • endAction: This is the name of the scene that the most recently viewed scene links to.
  • sceneID : This is the name of the most recent scene that the player has viewed.
  • moment : This is the most recent moment within the scene that the player has viewed.
  • Any additional values that you set through the methods above will be available to the rest of your game

By changing the value of endAction while a scene is playing, you will change the scene's outcome.
You can use sceneID and moment to launch the engine into the most recently viewed part of the dialog (restoring a previous game session, for example).

If you set a name/value pair in the register during your game, that value will be available to the Engine to see and use.

You can set end actions or choice button links to be variables: [r=marketSceneLink] instead of typing a scene name, which allows you to dynamically re-arrange how scenes play out based upon choices.

  • slidge/the_register.txt
  • Last modified: 2018/12/22 19:31
  • by journeyman