YEP.162 – Advanced Switches and Variables – RPG Maker MV

Yanfly Engine Plugins is a plugin library made for RPG Maker MV, a wonderful piece of software to help you make that role playing game of your dreams. You can find out more about RPG Maker MV here.

You can grab the plugin here:

English Mirror

Support Team Yanfly on Patreon.

For the advanced users out there with JavaScript experience, you can set certain switches and variables to return data about the game through pieces of code on the get go. This can be used for event page conditions, enemy AI conditions, troop page conditions, and more!


Introduction


For the advanced users out there with JavaScript experience, you can set certain switches and variables to return data about the game through pieces of code on the get go. This can be used for event page conditions, enemy AI conditions, troop page conditions, and more!


Instructions


To use this plugin, name the switches or variables that you want to utilize code effects with the following format:

Eval: code

This will make the switch or variable run the piece of code after the ‘Eval:’ marker. The code is used for a switch, it ought to return a ‘true’ or ‘false’ boolean. If the code is used for a variable, it ought to return a numeric value for comparison.

For example, a switch named ‘Eval: $gameActors.actor(1).isLearnedSkill(5)’, then it will return true if Actor 1 has skill 5 learned or not. This can be used for things like making a skill with ‘True Sight’ and making certain things appear visible on the map if the actor has that skill.

While variables can insert their own JavaScript code easily thanks to the help of the ‘Script’ option in the Control Variables event, you can save yourself the extra step by just naming a variable ‘Eval: $gameParty.gold()’. This will automatically make it calculate the amount of gold the party has and reference it with the variable.

!! WARNING !!

If you are using this as an event’s page condition, keep in mind that any changes made from events on the map will not reflect the changes made to reference those switches immediately. For that, you will have to refresh the map, which can be done using the plugin command below:


Plugin Commands


These plugin commands can be used to immediately refresh a map or troop troop event to ensure that switch/variable data gets noticed and triggered or updated upon your call.

Plugin Command:

RefreshMap
– This will refresh all of the map’s events. This will update any page conditions with Advanced Switches or Variables that may have changed values prior to using this plugin command. This can only be used outside of battle!

RefreshTroop
– This will refresh the current event interpreter in battle. This will update any page condition within the current troop that utilizes Advanced Switches or Variables that may have changed values prior to using this plugin command.
* NOTE: If you are using the Battle Engine Core, using this won’t be necessary for the majority of the time.


Examples


Here are some examples that you can use Advanced Switches and Variables for!

– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Switches
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –

Eval: $gameActors.actor(1).isLearnedSkill(5)
– This will make a check if Actor 1 (in the database) has learned skill 5 (in the database). This can be used for some skills like ‘True Sight’ to certain events appear differently on the map or certain events happen in battle (like seeing through an enemy’s disguise).

Eval: $gameActors.actor(3).isEquipped($dataWeapons[100])
– This will make a check to see if Actor 3 (in the database) has Weapon 100 (in the database) equipped. If it does, then the switch will return true. Otherwise, it will return false.

Eval: $gameActors.actor(4).isEquipped($dataArmors[200])
– This will make a check to see if Actor 4 (in the database) has Armor 200 (in the database) equipped. If it does, then the switch will return true. Otherwise, it will return false.

Eval: $gameVariables.value(2) < 3
– You know how map event page conditions can only make checks if a variable is only greater than or equal to a value? Well, now you can do the opposite and check if a variable is less than a certain value. The example used above will check if Variable 2 has a value less than 3 (but not equal to).

Eval: $gameSelfSwitches.value([10,20,’A’])
– This will allow an event to use another event’s self switch case to determine its condition. The example above checks if Map 10, Event 20’s ‘A’ self switch is turned on.

– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Variables
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –

Eval: $gameParty.leader().actorId()
– This will return the party leader’s actor ID. This can be useful for certain events that may have different reactions depending on who your party leader is at the time.

Eval: $gameParty.gold()
– This will return the party’s exact amount of gold. This can also be used in some event’s pages to make bags of gold appear in the player’s HQ to show just how rich the player is.

Eval: $gameParty.steps()
– This will return the amount of steps the player has walked. This can be used in ways where a trophy may appear in the player’s HQ depending on how many steps the player has walked.

Eval: $gameParty.aliveMembers().length
– This will return the number of alive members in the current party. Best if used in battle when trying to make different things happen depending on the number of allies currently alive in battle.

Eval: $gameParty.deadMembers().length
– This will return the opposite: the number of dead members in the current party. Also best used in battle when trying to make different things happen depending on the number of allies that are dead in battle.


Happy RPG Making!


Please wait while you are redirected...or Click Here if you do not want to wait.