MathScript Snippets: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 17: | Line 17: | ||
*<code>actions = arraySlice(actions, 0,4)</code> Get the first 4 actions of the 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. | *<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_resetWhich we store the day when this math script was run last.trainer_skillsWhere 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.