MathScript Snippets

From FetishQuest Wiki
Revision as of 17:47, 25 September 2025 by JasX (talk | contribs)
Jump to navigation Jump to search

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.