Advanced: Variable Utilities
Section 4.C.2
This subsection will introduce the midbattle variable and how it can be utilized within a midbattle script. Examples are provided to give a clearer picture in how this can be applied.
Manipulating the Variable's Value
By default, this variable is set to zero at the start of every battle. However, you can manipulate this variable's default value by manually setting it to the specific value you desire. To do this, we would use the "setVariable" Command Key.
In this example, the value of the variable is reset to zero at the end of every 4th turn. Something like this can be utilized if you want to have some sort of timer in battle that resets every four turns. This is a handy want of have some way to hard reset this variable once it has reached a value threshold that you needed it to.
If you want this variable to start counting in response to something, you may do so by utilizing the "addVariable" key. For example, let's say you want the variable to be increased by 1 at the start of each round in a battle.
You could use something like this to accomplish that. Now each turn, the variable's value will be increased by 1. If you want to reduce the variable's value instead, you would still use the "addVariable" key, except you would set this to a negative number instead. For example, if set to -1, then the variable would be reduced by 1 each turn.
If you want to randomize how much this variable should be changed by, you can instead set it to an array with as many different values as you want, and one of these values will randomly be selected to add to the variable's total value. For example:
This would add to the value at the start of each turn, but the amount would be randomly selected amongst the values in the array.
Finally, if you want to increase the variable's value by a certain factor rather than directly adding an amount, you can accomplish this with the "multVariable" Command Key.
In this example, the value of the variable will now double at the start of each round. If you would like to reduce the variable by a certain factor, you would still use the "multVariable" key, except you would set this to a float number instead. For example, if set to 0.5, then the variable would be reduced by half each turn.
Note: The value of the midbattle variable may never be less than zero. If you use any of the above methods to set or reduce the variable's value to a number less than zero, the variable will just default to zero. Keep this in mind when designing scenarios where the variable's value may decrease for some reason.
By utilizing "setVariable", "addVariable" and "multVariable", you have full control in manipulating the value of the midbattle variable. Now let's move on to how we can make something actually happen in response to this variable's value.
Responding to the Variable's Value
Any time you utilize the "addVariable" or "multVariable" Command Keys described in the above section of this page, a series of Trigger Keys are checked for. These are the keys you want to use in order to make something happen in response to the value of the variable changing. Note that "setVariable" does not trigger these keys.
When the Variable Reaches a Specific Value
Whenever the variable is changed, the "Variable_#" Trigger Key is checked for, where # corresponds to the specific value of the variable. For example, if you set the Trigger Key "Variable_2", this will trigger whenever the value of the variable equals exactly 2. Here's an example:
In this example, each time the player's Pokemon misses the opponent with a move, the variable's value is increased by 1 thanks to the "addVariable" Command Key. Once this value reaches 2, this will trigger a speech event thanks to the "Variable_2" Trigger Key where the opponent mocks you about your inaccuracy.
You can include as many "Variable_#" keys as you want in order to check for as many different variable values as you want. For example, we can expand upon the previous example so that the opponent will now say something each time the player misses, up to 3 times.
When the Variable Changes Value
If you want to respond to the variable changing value, but don't want to specify a particular value to check for, you may do so with the "VariableUp" and/or "VariableDown" Command Keys. Unlike the normal "Variable_#" key, these don't require any specific number value entered. Instead, these keys simply check the value of the variable to see if it has been changed by any amount since the last time it was changed. If so, the respective key will trigger depending on whether this amount has increased or decreased.
In this example, the opponent plays a game with the player at the end of each of the player's Pokemon's turns. During each instance, the opponent will "flip a coin." If the player wins the coin flip, their Pokemon has a random stat raised by one stage. If the player loses the coin flip, then their Pokemon has a random stat lowered by one stage. This is accomplished by using "setVariable" to reset the variable to 1 each turn. Then, "addVariable" is used to randomly add 1 or subtract 1 from this value, simulating a coin flip. Finally, the "VariableUp" or "VariableDown" Trigger Key will trigger depending on this outcome.
If you want something to happen when the variable's value is changed, but only if its new value is above or below a certain value, then you may do so by using the "VariableOver_#" and "VariableUnder_#" Trigger Keys, respectively. The # in these keys represent the number which the variable's value should be compared to.
In this example, the variable's value is increased by 1 each time the player uses an item from their bag. Once this variable reaches a value which is greater than 2, a speech event will trigger in which the opponent will comment on the player's repeated item use.
The same idea works in reverse when using "VariableUnder_#", which will trigger only when the variable's value has been reduced, but only if this value is less than the entered number.
Last updated