User:Haama/FAR
A Functional Activator Script is a type of global script that behaves like common programming functions. Like functions, they can:
- Be called from another script at any time
- Will happen immediately, before the next line of code is processed
- Can be nested (though note the limitation below)
- Take input parameters and can return output parameters
- Make your code easier to read and write
- Centralize sections of your code
Background
The script is really what defines the function, what it will do, and does the work. In most programming languages, you would simply write the function code, give it a name, and call it with the function's name. However, you're not able to simply call a script in Oblivion. Instead, FASs rely on some particular oddities of Activate to mimic function behavior.
there are 3 important parts here - the Activate call, the script, and the reference stuff (or hoops/hacks)
In which Bethesda makes things harder (or you realize this is a bit of a hack)
The script is really what defines the function, what it will do, and does the work. However, you're not able to simply call a script in Oblivion... like quests, added items have to use a function... here we use Activate, and so we need to have a reference to actually Activate...
Functional Activator Scripts rely on some particular oddities of the Activate function. When you use the onActivate flag of the Activate function, it will instantly run the Activated reference's script.
You have to call a specific reference. there are a few steps you need to go through to set up each Functional Activator.
- Before you make any Functional Activator you'll want to create an empty cell. You'll use this cell to hold all of the activators.
- Each Functional Activators require 3 parts: the script, the base activator, and the persistent reference activator. The script is the fundamental definition of the Functional Activator and is discussed
- The script needs an onActivate block and will generally look like
- Base Activator - it can be any object, but activators
...
empty cell, disable, persistent
...
can be any object, but activators are best
General description
What they're useful for
- Centralize code
- Simplify code - can put complex if tests in separate FAR
Maybe go in order from least to most complex
- onActivate only
- Inputs/Outputs/Variables
- Heart-beat
Limitations
- Only 4 within each other
- Careful with Labels/loops
- Will take more processing due to more set/if statements, but those take 1000s to become a problem
- Probably not a good idea to trust between save/load
Preference over other script types (should really be on Global page)
- Compared to quest scripts
- Run instantly
- No need to handle timing issues and flags
- Quest scripts may be more reliable for long-term scripts
- Run instantly
- Compared to result scripts
- Longer
- Can store variables, use ref variables in functions
- However, result scripts can have an infinite nest depth
- Compared to token
- Store the information
- Tokens better at keeping information for each actor, etc.
scn ScriptNameFAS ;FAS for Functional Activator Script, not necessary but helpful to keep scripts organized begin onActivate ;function code end