Rename your variables! Giving your variables clear names can help you search for them faster and recognize what is being used when you go back to look at older scripts. As you get familiar with variables, try to work with simple math and checks to practice. Keep it simple – variables, and their related events, are very powerful, and you can do a lot with variables. In later articles, we’ll cover the more advanced events and math using variables. There are many other ways we can manipulate or check variables, but understanding the basics of True / False and comparing Values are the core mechanics.
Great! We’ve now learned how Local and Global Variables interact, and how to check them to control different scripts.
If an event or math increases a variable above 255, or decreases it below 0, the variable will loop and continue counting! It’s important to keep this in mind – if you add or subtract too much, your scripts or game may not work because the values are not what you expect! You can use different events in GB Studio to change variable values. As you advance, you can start checking variables for specific numbers, and use those numbers or ranges to control things in your game. Checking if a variable is True or False is the simplest way to use a variable. If a variable is assigned a number above 0, it becomes true. What’s Stored in a Variable?Īll variables, regardless of type, can store a number between 0 and 255.Īll variables start at 0, or false, by default.
This may sound contradictory – if the point of a variable is to store information, why would we want it to be cleared? Temp variables are useful for manipulating other variables or creating menus – instead of using a Local or Global variable to track a menu selection for instance, or if a dialogue choice does not need to be remembered, you can use a temp variable in its place to free one of the Local or Global variables. In most cases, after a Temp variable is used, it is cleared from memory. However, Temp variables are not tracked like global variables: they are temporary. You have 2 temp variables to use in your scripts, and like Global Variables, the 2 temp variables are used across all Actors, Triggers, and Scenes. Scene Local Variable: checking if a script (like a cutscene) has already been played Trigger Local Variable: checking if you’ve stepped on a trap tile already Since Local Variables cannot be affected by other actors, triggers, or scenes, they have more limited uses than Global Variables, but are still quite useful!Īctor Local Variable: checking if you’ve opened a treasure chest already Every Actor, Trigger, and Scene in your game has 6 local variables to work with. Local variables are only stored within the Actor, Trigger, or Scene that owns them. If multiple actors, triggers, or scenes will need to know the information in the variable, you’ll want it to be global. Global variables are very useful for keeping track of information through your entire game, such as how much money the player has or whether or not they’ve completed a quest. Global variables can be tracked across scenes, actors, and triggers. (*Temp variables are only available in the 2.0 Beta) There are 3 types of variables in GB Studio: Global, Local, and Temp* variables, each type has its own uses. To make the most of variables in your game, it’s important to familiarize yourself with the types of variables and their limitations in GB Studio. They are empty containers that we can use to store a value, and later call on to change how our game works. Just like in math, variables in game design are placeholders for information.
In a math problem, such as “x + 2 = 4”, x is a variable – a way to represent a value that can change. If you have asked for help on how to do something in GB Studio, you’ve probably been told it can be done with variables.
You have probably heard the term “variable” in math class. If you’re working on a project in GB Studio, you’ll eventually need to work with variables, and this article will introduce you to the types of variables and how you can use them. Variables are used to store information, and you can use that information to control your game behind the scenes. Variables are one of the core components of building a game. Seasoned GB Studio devs may still find different ways to tackle challenges with these articles, so it should be worth the read. If you’re a GB Studio Beginner, then these articles are for you. In the “Basics” series, we’ll be going over all the technical foundations needed to start building a GB Studio game.