MathScript Snippets: Difference between revisions
Jump to navigation
Jump to search
Created page with "A collection of snippets you can use in math scripts. === Update a dvar array on new day. === In this example, we use a dungeon with the label <code>sfq_town</code> . We have the following dVars: * <code>last_trainer_reset</code> Which we store the day when this math script was run last. * <code>trainer_skills</code> Where we store an array of 4 action labels that we'll use in conditions to decide which skills are available at a trainer. <pre>setDvar("sfq_town","last_t..." |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 2: | Line 2: | ||
=== Update a dvar array on new day. === | === Update a dvar array on new day. === | ||
In this example, we use a dungeon with the label <code>sfq_town</code> | In this example, we use a dungeon with the label <code>sfq_town</code> with the following dVars: | ||
* <code>last_trainer_reset</code> Which we store the day when this math script was run last. | * <code>last_trainer_reset</code> Which we store the day when this math script was run last. | ||
* <code>trainer_skills</code> Where we store an array of 4 action labels that we'll use in conditions to decide which skills are available at a trainer. | * <code>trainer_skills</code> Where we store an array of 4 action labels that we'll use in conditions to decide which skills are available at a trainer. | ||
<pre>setDvar("sfq_town","last_trainer_reset","!$g_day") | The point of the script is to pick a random set of trainer skills each day to present to the player when visiting a trainer. We do this by having game actions checking if action labels are present in the trainer_skills dvar.<pre>setDvar("sfq_town","last_trainer_reset","!$g_day") | ||
actions = getAssetLabelsRegex('Action', '^sfq_pc') | actions = getAssetLabelsRegex('Action', '^sfq_pc') | ||
shuffle(actions) | shuffle(actions) | ||
Line 12: | Line 12: | ||
setDvar("sfq_town", "trainer_skills", actions)</pre>Explanation: | setDvar("sfq_town", "trainer_skills", actions)</pre>Explanation: | ||
* <code>setDvar("sfq_town","last_trainer_reset","!$g_day")</code> Sets a dvar called last_trainer_reset in the dungeon labeled sfq_town to the current day. | * <code>setDvar("sfq_town","last_trainer_reset","!$g_day")</code> Sets a dvar called last_trainer_reset in the dungeon labeled sfq_town to the current day. The !$ prefix in the setDvar function is used to mark that the rest of the data should be evaluated as a formula. g_day is a game mathvar (used in ALL formulas) and is an integer value specifying how many days have elapsed in the active game. | ||
* | *<code>actions = getAssetLabelsRegex('Action', '^sfq_pc')</code> Scans through the Action library and return an array of all actions starting with sfq_pc (^sfq_pc is a regular expression). | ||
*<code>shuffle(actions)</code> Shuffles the action array. | |||
*<code>actions = arraySlice(actions, 0,4)</code> Get the first 4 actions of the array. | |||
*<code>setDvar("sfq_town", "trainer_skills", actions)</code> Sets the trainer_skills dungeon var in the dungeon labeled sfq_town to the array of actions. | |||
Said mathScript game action is run every time the player enters the gym. |
Latest revision as of 17:49, 25 September 2025
A collection of snippets you can use in math scripts.
Update a dvar array on new day.
In this example, we use a dungeon with the label sfq_town
with the following dVars:
last_trainer_reset
Which we store the day when this math script was run last.trainer_skills
Where we store an array of 4 action labels that we'll use in conditions to decide which skills are available at a trainer.
The point of the script is to pick a random set of trainer skills each day to present to the player when visiting a trainer. We do this by having game actions checking if action labels are present in the trainer_skills dvar.
setDvar("sfq_town","last_trainer_reset","!$g_day") actions = getAssetLabelsRegex('Action', '^sfq_pc') shuffle(actions) actions = arraySlice(actions, 0,4) setDvar("sfq_town", "trainer_skills", actions)
Explanation:
setDvar("sfq_town","last_trainer_reset","!$g_day")
Sets a dvar called last_trainer_reset in the dungeon labeled sfq_town to the current day. The !$ prefix in the setDvar function is used to mark that the rest of the data should be evaluated as a formula. g_day is a game mathvar (used in ALL formulas) and is an integer value specifying how many days have elapsed in the active game.actions = getAssetLabelsRegex('Action', '^sfq_pc')
Scans through the Action library and return an array of all actions starting with sfq_pc (^sfq_pc is a regular expression).shuffle(actions)
Shuffles the action array.actions = arraySlice(actions, 0,4)
Get the first 4 actions of the array.setDvar("sfq_town", "trainer_skills", actions)
Sets the trainer_skills dungeon var in the dungeon labeled sfq_town to the array of actions.
Said mathScript game action is run every time the player enters the gym.