Difference between revisions of "User:Haama/FAR"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>Haama
m
imported>Haama
m
Line 8: Line 8:


==Background==
==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.
While FASs behave like functions, their set up is quite a bit different. 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.
 
Like many functions, '''Activate''' works upon a [[Reference|reference]]. When you use the ''RunOnActivate'' flag of '''Activate''', the reference's script runs instantly. In terms of functions, '''Activate''' calls the function, the reference is the function's name and the script is the function's code.
 
----
 
The script is really what defines the function, what it will do, and does the work.
 
There are 2 important ideas to know about '''Activate''': it acts upon a reference object, and it can run that reference's script instantly.


there are 3 important parts here - the Activate call, the script, and the reference stuff (or hoops/hacks)
there are 3 important parts here - the Activate call, the script, and the reference stuff (or hoops/hacks)

Revision as of 16:18, 26 March 2009

A Functional Activator Script is a type of global script that behaves like common programming functions. Like functions, they can:

  1. Be called from another script at any time
  2. Will happen immediately, before the next line of code is processed
  3. Can be nested (though note the limitation below)
  4. Take input parameters and can return output parameters
  5. Make your code easier to read and write
  6. Centralize sections of your code

Background

While FASs behave like functions, their set up is quite a bit different. 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.

Like many functions, Activate works upon a reference. When you use the RunOnActivate flag of Activate, the reference's script runs instantly. In terms of functions, Activate calls the function, the reference is the function's name and the script is the function's code.


The script is really what defines the function, what it will do, and does the work.

There are 2 important ideas to know about Activate: it acts upon a reference object, and it can run that reference's script instantly.

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.

  1. 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.
  2. 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
  1. The script needs an onActivate block and will generally look like
  2. scn ScriptNameFAS ;FAS for Functional Activator Script, not necessary but helpful to keep scripts organized
    
    begin onActivate
    ;function code
    end
  3. 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
    • 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.