🌱
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
  1. Overview
  2. Notes

Function in a Function

There are several cases where you might want to call a formula function within another one.

Let's say you wanted to create a formula function which requires additional conditions depending on if the target is undead. These additional conditions could be defined in other formula functions.

For example, formula function 0 could be checking whether the target has the safety augment, and if it does, set the formula skip state and miss state to 1 like this:

local function func(formula, caster, target, functions, classes, helpers)
  if target.temporaryAugments.safety == 1 or target.permanentAugments.safety == 1 then
    formula.skipState = 1
    formula.missState = 1
  end
end

return func

while formula function 1 could do the same but with the stability augment instead like this:

local function func(formula, caster, target, functions, classes, helpers)
  if target.temporaryAugments.stability == 1 or target.permanentAugments.stability == 1 then
    formula.skipState = 1
    formula.missState = 1
  end
end

return func

Now instead of duplicating that code in your new formula function, you can just call them like this:

local function func(formula, caster, target, functions, classes, helpers)
  if formula.target.classification == 13 then --13:Undead
    functions[0](formula, caster, target, functions, classes, helpers)
  else
    functions[1](formula, caster, target, functions, classes, helpers)
  end
  if formula.skipState == 1 then return end
  
  formula.power = formula.power * 2
end

return func

So if the target is undead, they must also not have the safety augment. If they are not undead, they must also not have the stability augment.

Make sure to pass the arguments of the current formula function along the one you are calling so it has the same capabilities as this one.

Since these formula functions were manually called and therefore not part of the formula's functions list, you must manually check whether the formula skip state was modified and if so, return preemptively.

If this was the case here, then all the following formula functions and the code that doubles the formula's power would be skipped.

Now you could technically do all of this via helper functions instead. However, this was only a very simple example. There are formula functions which call 3 or more other formula functions with dozen lines of code one after another.

So while helpers are usually used to do one specific task, functions do more complex ones.

PreviousLoopsNextHelpers

Last updated 1 year ago