🌱
The Insurgent's Forge
  • Home
  • Getting Started
    • Setup
    • Resources
  • Overview
    • Configuration
      • Formulas
      • Functions
      • Classes
      • Helpers
      • Assemblies
      • Middlewares
      • Dependencies
      • Options
      • Errors
    • Improvements & Additions
    • Structures & Parameters
    • Formula Workflow
      • Combo
      • Counter
      • Area of Effect
      • Reserve Party Member
      • Reflect
      • Mist
      • Trap
      • Chain Benefit
      • Summon
      • Spawn
      • Gambit
    • Limitations
      • Animations
      • Status Effects & Augments
    • Notes
      • Flags
      • Loops
      • Function in a Function
    • Helpers
      • Add Augment
      • Add Status Effect
      • Apply Knockback
      • Get Active Party Member
      • Get Action Status Effects
      • Get Augment Duration
      • Get Battle Unit Keep
      • Get Battle Unit Keep By Focus
      • Get Battle Unit Work
      • Get Character Max Hp
      • Get Character Max Mp
      • Get Character Type
      • Get Elemental Affinities Match
      • Get Equipment Status Effects
      • Get Forced Poach Rarity
      • Get Forced Steal Rarity
      • Get Formula Proc Keep
      • Get Knockback Range
      • Get Location Mist Strength
      • Get Model Evade Types
      • Get One Hit Kill State
      • Get Random Number
      • Get Reflect Target
      • Get Remedy Status Effects
      • Get Status Effect Duration
      • Get Status Effect Tick Duration
      • Get Status Effects Match
      • Get Terrain Type
      • Get Weather
      • Is Interactable
      • Modify Content
      • Modify Gil
      • Modify Hp
      • Modify Mist Charges
      • Modify Mp
      • Modify Sky Pirates Den Stats
      • Refresh Stats
      • Remove Augment
      • Remove Status Effect
      • Set Level
      • Shift Elements
      • Show Combat Log
      • Show Number Text
      • Teleport Location
  • Support & Updates
    • Changelogs
      • Version 1.0.3
      • Version 1.0.2
      • Version 1.0.1
      • Version 1.0.0
    • Known Issues
    • FAQ
Powered by GitBook
On this page
  • General
  • Notes
  1. Overview
  2. Notes

Loops

General

There are several ways to loop through flags (e.g. formula.target.statusEffects)

Let's say you wanted to create a formula function that doubles the formula's power for every status effect the target has. To do that, you could write something like this:

local function func(formula, caster, target, functions, classes, helpers)
  for i, v in pairs(formula.target.statusEffects) do
    if v == 1 then
      formula.power = formula.power * 2
    end
  end
end

return func

Now let's exclude the status effects protect and shell as another requirement. Since you have access to the status effect identifiers, you can easily add them to the current condition.

local function func(formula, caster, target, functions, classes, helpers)
  for i, v in pairs(formula.caster.statusEffects) do
    if i ~= 18 and --protect
       i ~= 19 and --shell
       v == 1 then
      formula.power = formula.power * 2
    end
  end
end

return func

As the next step, you could expect the caster to also have the same status effects. There are multiple ways to accomplish this, some a bit more readable than others.

For example, instead of looping through the status effects table, you could also loop through the status effect bits table directly. That way you have access to not only a status effect's identifier, but also its name.

local function func(formula, caster, target, functions, classes, helpers)
  for name, id in pairs(helpers.statusEffectBits) do
    if name ~= "protect" and
       id ~= 19 and --shell
       formula.caster.statusEffects[name] == 1 and
       formula.target.statusEffects[id] == 1 then
      formula.power = formula.power * 2
    end
  end
end

return func

The flags here are accessed via different ways for demonstration purposes. You can choose whichever way suits your coding style more.

Notes

All entries in a metatable (list, flags, ...) start with 0, not 1. This is intended as that way the table key (e.g. 0 -> KO) is identical to the identifier used by the game.

Due to technical limitations, you cannot loop through a metatable (list, flags, ...) via the ipairs function. Instead, you can use the pair function, or loop through it manually via its length.

PreviousFlagsNextFunction in a Function

Last updated 5 months ago