Validate Script
Context: HL Kit … Kit Reference … Script Types
Technical Details
The Validate script utilizes the following special symbols:
valid Entry: Assumes the pre-requisite is not satisfied with a value of zero.
Exit: Indicates whether the pre-requisite is satisfied (non-zero) or not satisfied (zero).
message Entry: Contains the default message text if the pre-requisite is not satisfied.
Exit: Contains the final message text to display if the pre-requisite is not satisfied.
ispick Entry: Indicates whether the pre-requisite is being applied to a pick (non-zero) or thing (zero).
Exit: Ignored.
Description
The Validate script is exclusively used within pre-requisite tests. The script verifies that a specific pick or thing satisfies a particular pre-requisite relative to its container. If the requirement is not satisfied, then the object is designated as invalid. If the object is a pick that has already been added to the portfolio, the specified message is displayed within the validation report for the actor.
The pre-requisite test can be anything you want, provided only the object and the container are considered by the test. The requirement is always either satisfied or not satisfied. This is determined by the "valid" special symbol. The symbol starts out as zero, indicating that the requirement is not satisfied. At any point during the script, you can set the symbol to non-zero, thereby indicating that the requirement is satisfied. The only value that matters is the final value when the script ends, where a non-zero value indicates the pre-requisite is satisfied.
Since an EvalRule script is equivalent to an Eval script, it is possible to apply changes throughout the structural hierarchy via the script. However, it is generally a bad idea to do that, since the purpose of an EvalRule script is to validate a rule - not effect change. We therefore recommend that you avoid applying changes within EvalRule scripts.
Since the message and summary are typically static requirements (e.g. an attribute must be a value of X or more), you will rarely need to modify them. However, there will be cases where you want to tailor the message and/or summary to provide more detailed information based on dynamic information. When this situations arise, simply set the "message" and/or "summary" special values to the desired contents and they will be used.
Like an Eval script, every EvalRule script is associated with a particular thing. If an EvalRule script is defined for component, then it is inherited by the things which derive from that component. When a thing is added to a container, it becomes a pick, and new instances of every EvalRule script for that thing are created and managed by HL. You associate all of the validation rules with each pick via the EvalRule scripts defined for the underlying thing.
When invoked, an Eval script starts with its associated pick as its initial context. You are free to navigate through the hierarchy and test the state of anything that impacts the rule. However, a given EvalRule script should will typically either pertain to the associated pick or pertain to the actor as a whole.
Example
An EvalRule script can be used to test virtually anything. Within the Sample data files, a rule is used to ensure that pieces of gear are not both equipped and held within a container (e.g. a sword being equipped and stored in a backpack). The rule below will verify this condition.
~if not both equipped and held within a container, we're valid if (field[grIsEquip].value + isgearheld < 2) then @valid = 1 done endif ~mark the tab as invalid linkvalid = 0