Advanced Script Handling

From HLKitWiki
Revision as of 17:37, 28 November 2008 by Rob (Talk | contribs) (New page: {{context|Advanced Authoring Concepts}} The Kit provides a variety of more specialized control mechanisms for managing scripts. These mechanisms provide the ability to handle special-case...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Context: HL KitAdvanced Authoring Concepts 

The Kit provides a variety of more specialized control mechanisms for managing scripts. These mechanisms provide the ability to handle special-case situations that may arise when writing data files for some game systems. The topics below cover these various mechanisms.

Sequencing of Scripts with Identical Timing

When multiple tasks are assigned a common phase and priority, those tasks will be scheduled for evaluation at the exact same time. However, the task scheduler only invokes one task at a time. This means that there would be no guarantee about the order in which two tasks are evaluated that are assigned the same timing. From an authoring standpoint, it's much easier to assign a group of tasks the same phase and priority instead of having to micro-manage which ones occur before each other.

To address this, the Kit provides a set of rules for task scheduling. These rules govern the sequence in which tasks are evaluation that have the same phase and priority. The table below details the order that the Kit uses, with tasks being evaluated in the sequence given, based on their type.

  1. Existence tests that are assigned by tables or choosers
  2. Bootstrap condition tests that are assigned by root picks
  3. Secondary tests that are assigned by tables or choosers
  4. Condition tests that are assigned by components
  5. Condition tests that are defined explicitly on a thing
  6. Calculate scripts defined on any fields
  7. Bound scripts defined on any fields
  8. Eval scripts that are defined on components or things
  9. Evalrule scripts that are defined on components or things
  10. Gear scripts that are defined on components

The above rules don't handle a common situation that arises when component scripts are employed. The following topic address how this situation is handled.

Sequencing of Component Scripts

When an eval script or evalrule script is defined for a component, all things derived from that component possess the same script. Since the script is assigned a common phase and priority, all instances of that script will be scheduled for evaluation at the exact same time. As discussed above, the task scheduler only invokes one task at a time, so this means that there is no guarantee about the order in which these scripts are evaluated.

In most cases, there is no need to worry about the respective timing of these scripts, since they don't depend on each other. However, there are situations where it's important that all the scripts being evaluated in a guaranteed order. For example, consider the d20 System data files, where attribute bonuses are chosen every four character levels. It's critical that those bonuses be applied in the exact order that they are selected by the user, since those bonuses have ripple effects elsewhere on the character. Consequently, the Kit imposes rules on the evaluation sequencing of component scripts.

Every component must be assigned a "sequence" attribute. This attribute governs how picks are sequenced to the user by default. It also governs how their tasks will be sequenced during evaluation. Consequently, during task scheduling of eval scripts/rules that are associated with the same component, the corresponding tasks are sorted using the sequence assigned to the component. This ensures that tasks are always scheduled in a consistent fashion. It also extends to the case where things are added multiple times to a container.

In rare situations, you'll need to specify an alternate behavior for task scheduling. To accommodate these cases, individual scripts and rules have an attribute that overrides their behavior. This attribute allows to you specify a different component whose sorting rules must be used when scheduling all tasks for that script.