Scripting: Variables/Switches

Variables and switches are important in GG Maker and the development of games when it comes to storing information.

Switches can hold one of two values at any one time: ON or OFF. Unless indicated through the Global Variables/Switches/Collections menu, a switch’s default value will be OFF at the start of the game, but can be turned ON and OFF through events in your game. These can be used for simple situations that only need a yes/no answer to progress, such as if part of the story has been completed, a particular NPC has been interacted with, or perhaps an enemy has been killed.

Variables can hold any numeric value which can also be set through events in your game, or a default can be set in the Global Variables/Switches/Collections menu. These can be used to hold information for numbers, such as gold, the amount of enemies the player has killed, how many steps a player has taken, etc.

The Global Variables/Switches/Collections menu will present you with four options. These can be edited individually, allowing you to choose the maximum amount of variables/switches in your game, name them for later identification, and set their default values. The four options you can edit are:

Global Variables 

These variables are common throughout the project. This means they can be called from anywhere at any time, and are important to use for information that needs to be viewed regularly, such as a player’s name for dialogue or the player’s money.

Switches 

Switches are always either ON or OFF. They are useful for keeping track of whether a certain event has been completed and whether a new event has been unlocked, for example. Like Global Variables, Switches are accessible throughout the entire project.

<p class="MsoNormal" style="margin-bottom:0cm;margin-bottom:.0001pt"><span style="font-size:12.0pt;line-height: 107%;font-family:"CalibriLight",sans-serif;mso-ascii-theme-font:major-latin; mso-hansi-theme-font:major-latin">Collections 

<p class="MsoNormal" style="margin-bottom:0cm;margin-bottom:.0001pt"><span style="font-size:12.0pt;line-height:107%;font-family:"CalibriLight",sans-serif; mso-ascii-theme-font:major-latin;mso-hansi-theme-font:major-latin">Collections are a way of holding a series of text or numbers, which can be added to or removed from. They can be used to store things like inventory information, and then used to populate an Interface like an inventory screen or a shop. The two events ‘Add to Collection’ and ‘Remove from Collection’ can be used to add and remove items from a shop’s stock respectively.

<p class="MsoNormal" style="margin-bottom:0cm;margin-bottom:.0001pt"><span style="font-size:12.0pt;line-height: 107%;font-family:"CalibriLight",sans-serif;mso-ascii-theme-font:major-latin; mso-hansi-theme-font:major-latin">Tables 

<p class="MsoNormal" style="margin-bottom:0cm;margin-bottom:.0001pt"><span style="font-size:12.0pt;line-height:107%;font-family:"CalibriLight",sans-serif; mso-ascii-theme-font:major-latin;mso-hansi-theme-font:major-latin">Tables can store a grid of text or numbers. These can be used for storing a lot of information that would otherwise require a large amount of separate Global Variables.

<p class="MsoNormal" style="margin-bottom:0cm;margin-bottom:.0001pt"><span style="font-size:12.0pt;line-height:107%;font-family:"CalibriLight",sans-serif; mso-ascii-theme-font:major-latin;mso-hansi-theme-font:major-latin">For instance, tables can be used when creating platformer games with multiple levels, and keeping track of each time the player completes a level. A table could store all of that information in a grid instead. Using ‘Repeat Loop’ and creating a Local Variable which goes up incrementally with each cycle could store all of that information quickly without the need to create a large list of ‘Edit Table’ events.

<p class="MsoNormal" style="margin-bottom:0cm;margin-bottom:.0001pt">

<p class="MsoNormal" style="margin-bottom:0cm;margin-bottom:.0001pt">

<p class="MsoNormal" style="margin-bottom:0cm;margin-bottom:.0001pt"><span style="font-size:12.0pt;line-height: 107%;font-family:"CalibriLight",sans-serif;mso-ascii-theme-font:major-latin; mso-hansi-theme-font:major-latin">Other Variables 

<p class="MsoNormal" style="margin-bottom:0cm;margin-bottom:.0001pt"><span style="font-size:12.0pt;line-height:107%;font-family:"CalibriLight",sans-serif; mso-ascii-theme-font:major-latin;mso-hansi-theme-font:major-latin">There are other types of variables not accessible through this menu, such as:

<p class="MsoNormal" style="margin-bottom:0cm;margin-bottom:.0001pt"><span style="font-size:12.0pt;line-height: 107%;font-family:"CalibriLight",sans-serif;mso-ascii-theme-font:major-latin; mso-hansi-theme-font:major-latin">Local Variables 

<p class="MsoNormal" style="margin-bottom:0cm;margin-bottom:.0001pt"><span style="font-size:12.0pt;line-height:107%;font-family:"CalibriLight",sans-serif; mso-ascii-theme-font:major-latin;mso-hansi-theme-font:major-latin">The variables are created within a script and can only be used within that script. Local variables will not be accessible outside of the script they were created in. Their main use is temporary data in one script, such as counting how many times the player has made the same dialogue choice.

<p class="MsoNormal" style="margin-bottom:0cm;margin-bottom:.0001pt"><span style="font-size:12.0pt;line-height:107%;font-family:"CalibriLight",sans-serif; mso-ascii-theme-font:major-latin;mso-hansi-theme-font:major-latin">Local Variables can be made persistent by checking the box next to their name. Persistent local variables remember any data stored in them after a script has ended, meaning their information can be reused later if the script is run again.

<p class="MsoNormal" style="margin-bottom:0cm;margin-bottom:.0001pt"><span style="font-size:12.0pt;line-height: 107%;font-family:"CalibriLight",sans-serif;mso-ascii-theme-font:major-latin; mso-hansi-theme-font:major-latin">Map/Interface Variables 

<p class="MsoNormal" style="margin-bottom:0cm;margin-bottom:.0001pt"><span style="font-size:12.0pt;line-height:107%;font-family:"CalibriLight",sans-serif; mso-ascii-theme-font:major-latin;mso-hansi-theme-font:major-latin">Similar to Local Variables, these can be created in Map/Interface property dialogues and can be used on the Map or Interface in which they were created, but these can also be called throughout the game through the ‘Map Variable’ and ‘interface Variable’ use values.

<p class="MsoNormal" style="margin-bottom:0cm;margin-bottom:.0001pt"><span style="font-size:12.0pt;line-height: 107%;font-family:"CalibriLight",sans-serif;mso-ascii-theme-font:major-latin; mso-hansi-theme-font:major-latin">Actor Variables  <p class="MsoNormal" style="margin-bottom:0cm;margin-bottom:.0001pt"><span style="font-size:12.0pt;line-height:107%;font-family:"CalibriLight",sans-serif; mso-ascii-theme-font:major-latin;mso-hansi-theme-font:major-latin">These are created in the Actor property dialogue and can be used on the Map in which they were created, but these can also be called throughout the game through the ‘Actor Variable’ use value with the exception of actor variables which have been created within an Actor Template. These can only be accessed through the Actor Template in which they were created.