Data/Validators/Function

Line + in a Function Validator opens up a window that allows you to create a system of Validators that function similar to if-then-else. This system allows you to dynamically change how the Function Validator reacts based upon which Validator in the list passes first. These are currently being used by the Tactical AI Data tab in determining how the AI plays.
In Coding Terms
for each line in lines end
In Layman's Terms
It is important to understand how Validators are considered "passed." A Validator can enable or disable Find. When disabled, if the target doesn't meet the conditions, it is considered passed. Thus if you were looking for a specific unit and it didn't find it, the Validator would allow whatever you validated to happen. When enabled, the opposite is true. If the target doesn't meet the conditions, the Validator disallows whatever you validated from happening.

## Field categories

### Validator: Line

Each line and its slot reads from the right to the left. For example, a failure slot will be checked before a success slot.

To help understand, each slot name will be in **Bold** characters.

Here are the slots:

* **Index:** Determines the order in which lines of Validators are checked. Standard top to bottom.
* **Break:** Stops the Function Validator once a line with this is enabled. Useful for testing long lists. Still follow the rules of "everything is skipped" (see below).
* **Failure:** If the inserted Validator is true, the Function Validator returns failure. All following lines are discarded. As it seems, using a sole failure entry in the first line, even if returning false, will fail the whole validator even before all the other lines have been checked. To counter this, use an invalid success entry to allow the validator to procceed and check other lines.
* **Ignored:** (Unkown, requires testing)

* **Return:** Is a condition that can deceide the fate of this function validator (success or faillure).
	+ If used alone (**Test** slot being empty), deceides the fate of this function validator as in success or faillure based on the inserted validator only. All other lines are discarded.
	+ If used in duo (**Test** slot has a validator in it), requires **Test** validator to return true, so that it can be used (otherwise the line is skipped). If the **Test** validator returns true, this **Return** validator will determine the success or failure of the whole function validator.

* **Success:** If the inserted Validator is true, the Function Validator returns success. All following lines are discarded. Remember that the
	+ On its own **Success** is not a "condition" to meet in order for the function to work. it is just a shortcut for returning it true.
	+ If used alone (**Test** slot being empty), can only trigger a success or be skipped if it returns false. This is the main difference with **Return** that fails the whole validator if it returns false, while Success is simply **ignored**.
	+ If used in duo (**Test** slot has a validator in it), requires **Test** validator to return true, so that it can be used (otherwise the line is skipped). If the **Test** validator returns true, this **Success** validator will determine the success or skip the line.
* **Test**: Is a trigger (based on its validator returning true) that becomes a condition for using **Return** and/or **Success** in the same line.
	+ If used and returns true, the **Return** and **Success** will determine if this whole function validator returns true/false or skip to the next line.
	+ If used and returns false, is ignored and the line is skipped, including the **Return/Success** validator.
	+ If used while having the **Return**/**Success** slot empty, is ignored and the line is skipped.

#### If everything is skipped:

If all lines are ignored/skipped, this validator returns true (Success slot is only a secondary way to it) for as long as one doesn't touch the **Result Fallback** field. Since this field is being set to "OK", which is a bugged error message that passes this validator no matter what, the Fallback field is the result of all the lines being check. Putting "Error" for example will invert the outcome, making this validator unable to succeed unless using a "Sucess" case or a "Test" + "Return"/"Success" combo.

* A good methodology to transform this validator in a form of "or" combine, along with conditions that makes it invalidated is to put as a last validator something that is 100% sure to fail. In such case, the validator will only responds to the successful conditions, and not give up a free success just because the lines have all been skipped.

#### Priorities summary

These are priorities between slots, on a single **Index**. The previous section implicitly explains it, but a little summary may help understand:

1. **Failure:** Prime on everthing on the line. Ends up true (leading validator to failure) or ignored.
2. **Ignored:** (Unsure)
3. **Test**: Primes on **Return** or **Success**, preventing them from usage as long as it doesn't return true. Else, is ignored.
4. **Return:** Primes over **Success**. Ends up true or false.
	* In combo with **Test**: Ends up true or false, does not prevent the **Success**/**Test** combo.
5. **Success**: Ends up true or ignored. Is equal to **Return** when managed by **Test**.
	* In combo with **Test**: Ends up true or ignored, does not prevent the **Return**/**Test** combo.
6. **Break**: Does its purpose afterward.

#### Another way to put it

```
 if (line.ignored.assigned)
   execute(line.ignored)
 if (line.test.assigned && !execute(line.test))
   continue
 if (line.failure.assigned && execute(line.failure))
   return ResultFailed
 if (line.success.assigned && execute(line.success))
   return Success
 if (line.return.assigned)
   return execute(line.return)
 if (line.break)
   break

```

### Validator: Result Fallback

Error message that will occur if all lines are skipped/ignored. Since this is set to "OK" by default, the result will always succeed. Changing it to other types of error message will invert the outcome of this validator, provoking the necessity of a successful line, or otherwise this validator will fail.