Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[XP] Variables Tutorial

Variable Tutorial



Introduction


Now first, you may ask...what is a variable? What does it do? What can it be used for? I will answer all these questions in the following paragraph.
In math terms, a variable is a non-numerical value (such as x or a) that is the placeholder for an unknown number, and commonly used in algebra, mainly for "solve for x" like problems. However, in the RPG Maker series for the PC (2000, 2003, XP, and VX) a variable is a value that can store a number (such as...203 or 376042838703...long eh?) for reference later and for eventing but also can be made to store system values such as the party's current gold or actor two's Max-SP. Methods like this can be used in eventing to create systems such as a HP/SP display or something to check if the player has enough gold.



Variable Guide


Now, we will go in depth of what a variable can do and what it is used for. So, kiddo...let's open a new RPG Maker XP project, and start a new project. Once you do that...double click a tile on the map to create a new event and double click the box to bring up a list of event commands. See the one called "Change Variables..."? Click that one. Now, I will use a screenshot to explain all functions, and I'll even explain the ones that are not so obvious.

Guide
variableswindowguide.png




1) This is the main window, with options for selecting a single variable and selecting a batch number of them. So, the first option allows you to select the variable for this operation and the second one allows you to select a batch number of them. For example, variables four to 9.

____________________________________________________________________________________________


2) Operation is a set of mathematical equations that can be used with variables. Set well...sets the variable to that specific value such as a system value or number. Add adds a number or system value to the variable, Sub does the opposite in which it subtracts a value, Mul multiplies the value, Div divides the value, and the last is Mod; Mod is special. It divides the variable by the number or system value and stores the remainder, unlike dividing it; which does not. Dividing a value or number only would store the result, not the remainder.

____________________________________________________________________________________________


3) Operand is simply a list of what you can do with a variable. Don't know how to make it any clearer.

____________________________________________________________________________________________


4) Constant sets the variable to a specific number (the one you pick), or does what you can do in number two; operation (add, sub, mul, div, mod).

____________________________________________________________________________________________


5) This function makes the variable equal itself or another variable. For a different variable than the one being than itself, the first variable's value is discarded and then made to match the second variable's value. Some examples:
Example 1: Variable 1=0/Variable 2=4. Variable 1=4.
Example 2: Variable 1=35/Variable 2=32. Variable 1=32.

____________________________________________________________________________________________


6) This makes the variable's value a random number among number x and number y. For example:
number four and number six (4, 5, 6). Random thus...5. Yes, I did use a random generator.

____________________________________________________________________________________________


7) This function makes the variable match the quantity of an item in the inventory. For example:
you have 16 Potions. You can use this function to make a variable match that, and it will change with the item's quantity. Variable 1=16. Now...let's add three Potions. Variable 1=19. Now let's take one away. Variable 1=18. Now let's take 17 away. Variable 1=1. Now let's take one away. Variable=0. Get it?

____________________________________________________________________________________________


8) This function makes the variable match an actor's stats. First drop-down function let's you select the actor and the second let's you select a stat. What you can select for the second: Level, EXP, HP, SP, MaxHP, MaxSP, Str, Dex, Agi, Int, Atk, Pdef, Mdef, and Eva.

____________________________________________________________________________________________


9) It's the same as number six but for enemies (monsters.) Six and seven are useful for making a scan like ability.

____________________________________________________________________________________________


10) Make the variable match an event or the player's Map X, Map Y, Screen Y, Screen X, Direction, and Terrain Tag. For example, you could use the Terrain Tag part to make a Geomancy skill.

____________________________________________________________________________________________


11) This one is other options, which are: Map ID, party members, gold, steps, play time, timer, and save count. RMXP's "What's this?" function does not explain save count, but it's just a count of the player's total saves to their current save file.

____________________________________________________________________________________________





Questions & Answers



Any further questions? Here's a FAQ.

Q: How would I make a "_____" event system with variables?
A: Find out for yourself. Experiment with the variables until you get what you want, and read tutorials.

____________________________________________________________________________________________


Q: I wasn't listening completely. WHAT is a variable again?
A: A variable is a function in RMXP where a number or system value can be stored in for reference or for eventing. That's the basics.

It's actually surprising to note that in all modern video games, variables AND switches are used. Let's take Sonic Adventure 2 for example. Let's say you're playing one of Knuckles' stages...let's pick Pumpkin Hill (one of my favorite levels in SA2). The game would logically create a variable to match the current number of master emerald shards Knuckles has found. Now, when the value of this variable equals three, it runs a check for that and brings up the stage complete screen thingie. Now I wanna play SA2 again...

____________________________________________________________________________________________


Q: What does it do?
A: It stores a value. Whether that's a number or a system value in RMXP, but scripting can also be used to make it store text instead! The script command for that is [$game_variables[vID] = "text"], without the brackets.

____________________________________________________________________________________________


Q: What can it be used for?
A: Checking values (such as actor's five Max-HP, or the player's current gold), and then using conditional branches for true or false. This can be used to make event systems...like Geomancy or a skill's power that increases with the quantity of a certain item, such as a Super Potion.
 

Star

Sponsor

This is a good tutorial but you missed two numbers or you go your numbers messed up cause it's a list of 9 but you have 11 points on your image. Might wanna fix that before you confuse the varinewbs
 
Also, one more thing you might want to look at is formatting. Its a good tutorial but its a real turnoff when words are cramped together in a giant paragraph. Spacing, bold font, and titles really help clean up posts.
 
More Spacing, its still a clump of words. I threw something together. Its not perfect or anything, but im too lazy to find the color codes for titles and line. Remember, make it easy to read and space it out right. Clumping seriously turns off readers. Clean tutorials have far more success.

Variable Tutorial



Introduction


Now first, you may ask...what is a variable? What does it do? What can it be used for? I will answer all these questions in the following paragraph.
In math terms, a variable is a non-numerical value (such as x or a) that is the placeholder for an unknown number, and commonly used in algebra, mainly for "solve for x" like problems. However, in the RPG Maker series for the PC (2000, 2003, XP, and VX) a variable is a value that can store a number (such as...203 or 376042838703...long eh?) for reference later and for eventing but also can be made to store system values such as the party's current gold or actor two's Max-SP. Methods like this can be used in eventing to create systems such as a HP/SP display or something to check if the player has enough gold.



Variable Guide


Now, we will go in depth of what a variable can do and what it is used for. So, kiddo...let's open a new RPG Maker XP project, and start a new project. Once you do that...double click a tile on the map to create a new event and double click the box to bring up a list of event commands. See the one called "Change Variables..."? Click that one. Now, I will use a screenshot to explain all functions, and I'll even explain the ones that are not so obvious.

Guide
variableswindowguide.png




1) This is the main window, with options for selecting a single variable and selecting a batch number of them. So, the first option allows you to select the variable for this operation and the second one allows you to select a batch number of them. For example, variables four to 9.

____________________________________________________________________________________________


2) Operation is a set of mathematical equations that can be used with variables. Set well...sets the variable to that specific value such as a system value or number. Add adds a number or system value to the variable, Sub does the opposite in which it subtracts a value, Mul multiplies the value, Div divides the value, and the last is Mod; Mod is special. It divides the variable by the number or system value and stores the remainder, unlike dividing it; which does not. Dividing a value or number only would store the result, not the remainder.

____________________________________________________________________________________________


3) Operand is simply a list of what you can do with a variable. Don't know how to make it any clearer.

____________________________________________________________________________________________


4) Constant sets the variable to a specific number (the one you pick), or does what you can do in number two; operation (add, sub, mul, div, mod).

____________________________________________________________________________________________


5) This function makes the variable equal itself or another variable. For a different variable than the one being than itself, the first variable's value is discarded and then made to match the second variable's value. Some examples:
Example 1: Variable 1=0/Variable 2=4. Variable 1=4.
Example 2: Variable 1=35/Variable 2=32. Variable 1=32.

____________________________________________________________________________________________


6) This makes the variable's value a random number among number x and number y. For example:
number four and number six (4, 5, 6). Random thus...5. Yes, I did use a random generator.

____________________________________________________________________________________________


7) This function makes the variable match the quantity of an item in the inventory. For example:
you have 16 Potions. You can use this function to make a variable match that, and it will change with the item's quantity. Variable 1=16. Now...let's add three Potions. Variable 1=19. Now let's take one away. Variable 1=18. Now let's take 17 away. Variable 1=1. Now let's take one away. Variable=0. Get it?

____________________________________________________________________________________________


8) This function makes the variable match an actor's stats. First drop-down function let's you select the actor and the second let's you select a stat. What you can select for the second: Level, EXP, HP, SP, MaxHP, MaxSP, Str, Dex, Agi, Int, Atk, Pdef, Mdef, and Eva.

____________________________________________________________________________________________


9) It's the same as number six but for enemies (monsters.) Six and seven are useful for making a scan like ability.

____________________________________________________________________________________________


10) Make the variable match an event or the player's Map X, Map Y, Screen Y, Screen X, Direction, and Terrain Tag. For example, you could use the Terrain Tag part to make a Geomancy skill.

____________________________________________________________________________________________


11) This one is other options, which are: Map ID, party members, gold, steps, play time, timer, and save count. RMXP's "What's this?" function does not explain save count, but it's just a count of the player's total saves to their current save file.

____________________________________________________________________________________________





Questions & Answers



Any further questions? Here's a FAQ.

Q: How would I make a "_____" event system with variables?
A: Find out for yourself. Experiment with the variables until you get what you want, and read tutorials.

____________________________________________________________________________________________


Q: I wasn't listening completely. WHAT is a variable again?
A: A variable is a function in RMXP where a number or system value can be stored in for reference or for eventing. That's the basics.

It's actually surprising to note that in all modern video games, variables AND switches are used. Let's take Sonic Adventure 2 for example. Let's say you're playing one of Knuckles' stages...let's pick Pumpkin Hill (one of my favorite levels in SA2). The game would logically create a variable to match the current number of master emerald shards Knuckles has found. Now, when the value of this variable equals three, it runs a check for that and brings up the stage complete screen thingie. Now I wanna play SA2 again...

____________________________________________________________________________________________


Q: What does it do?
A: It stores a value. Whether that's a number or a system value in RMXP, but scripting can also be used to make it store text instead! The script command for that is [$game_variables[vID] = "text"], without the brackets.

____________________________________________________________________________________________


Q: What can it be used for?
A: Checking values (such as actor's five Max-HP, or the player's current gold), and then using conditional branches for true or false. This can be used to make event systems...like Geomancy or a skill's power that increases with the quantity of a certain item, such as a Super Potion.
 
I have a question. How would I go about displaying a variable in a message?
Say I've had an invisible variable that counts up by 1 every time a chest is opened.
And I wanted a cliched "Psychic Hermit" to tell the player how many they'd opened.

"You've found 458 of the world's 1000 chests. Keep it up!"

I heard that it was possible to do this without scripting, but I don't know how.
 
Dachimotsu":2q5pw9v3 said:
I have a question. How would I go about displaying a variable in a message?
Say I've had an invisible variable that counts up by 1 every time a chest is opened.
And I wanted a cliched "Psychic Hermit" to tell the player how many they'd opened.

"You've found 458 of the world's 1000 chests. Keep it up!"

I heard that it was possible to do this without scripting, but I don't know how.
Yeah, to display a variable, write \v[#] where # is the variable's ID.
 
Neat! Are there any other tricks like that? (off-topic, I know, but since we're talking about it...)

EDIT: Never mind, I found a FAQ for it.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top