How tasks work
|THE MAIN ITEMS|
|---- Executing sub-tasks|
|---- How tasks work|
When the player types a command, ADRIFT searches through the command lines specified in all of the general tasks, looking for one which matches the players input.
It does this in priority order, from smallest priority number to highest, until it finds a match.
If the matching command contains references (%object%,%character%,%location% etc.) then a search is made through the items in the game to see if any match what the player typed at that possition in the command.
If more than one could be a match then ADRIFT tries to find the most appropriate by first testing if they would pass the task restrictions, then checking if the player has ever seen them, and finally checking if they are currently visible. If ADRIFT cannot find one best match then it asks the player which of the possible items that they mean.
If the general task does not pass its restrictions with any possible item, then one of two things can happen:
If the "Task execution logic" on the Advanced page of Options is set to the second option, or the failing restriction does not output any text, then ADRIFT looks for another general task that matches the players input and passes its restrictions, and runs that instead.
When a general task does pass its restrictions, ADRIFT checks for any specific tasks that have been set to override it.
Specific tasks which are set to "Run before" or "Override" the general task are checked in priority order.
If any of these matches its specific item and passes its restrictions, its actions are run and its "Message to display on completion" is shown.
Any lower priority specific tasks are only run if this one has its "Multiple matching" option set on the Advanced page.
The actions and completion message of the general task are now run, but not if an "Override" task ran, or if any of the "Run before" tasks that ran had its "Display parent message" or "Execute parent actions" boxes unticked.
Finally, the "Run after" specific tasks are run, in priority order.
This is a step-by-step description of how ADRIFT processes a players command and chooses which tasks to run.
It is not meant to be read through start to finish, it is provided as a reference for more advanced ADRIFT uses to help design more complex multiple-task commands and debug problems.
- The %Turns% counter is incremented as soon as the command is entered, so all of the tasks and events that follow will see the same value. %Turns% is zero when the introduction and any "immediately" system tasks are run at the start of the game, and 1 after the first command is entered.
- The first thing the parser does is replace the words "it", "them", "him" and "her" with the appropriate object or character that the player most recently refered to.
- The parser now checks each general task, starting from the one with the lowest number in the "Task Priority:" field on its "Advanced" page and proceeding in order until it finds a match between the player's input and one of the command lines of a task, using "Advanced Command Construction" matching.
- When it finds a matching general task, it now tries to match the references. Eg.If the command contains an %object% reference then ADRIFT searches through all of the objects in the game trying to find one which matches what the player typed in that part of the input. Note that the player may have entered the names of several objects, eg. "the watch and the pendant" or "all except the hat" or "pens" (which can mean all objects with "pen" as the noun if no objects are called "pens"). All of these must match items in the game.
- The player may have typed an ambiguous name that matches several items in the game, for example "pen" could match "red pen", "blue pen" or "green pen" if these all exist. To decide which one the player meant, ADRIFT uses a "scope" system to help choose between them.
- The first thing scope does is to check the items against the restrictions of the general task, if only one of them passes then it is assumed to be the one the player meant.
- If more than one passes restrictions then scope checks to see if one of those is currently visible to the player and chooses it.
- If none of them are currently visible, then scope checks to see if one of the items has ever been seen by the player.
- If more than one item passes these scope checks, then the player is asked a disambiguation question such as "Do you mean the red pen, the blue pen or the green pen?" to determine which item they meant.
- ADRIFT has now matched all of the objects, characters and/or locations that the player mentioned to the references in the command, so it can start to execute the task. If there are multiple items for a reference then ADRIFT executes the task once for each item, but only displays the text box once. Functions in the text box which have a different result are combined into a list, so if we run the task for the objects "a blue pen", "a gold coin" and "a flower" then the text "You pick up %object%.Name" is displayed as "You pick up the blue pen, the gold coin and the flower"
- The restrictions of the general task are now checked. If a restriction fails then ADRIFT skips that general task and resumes searching through the lower priority general tasks for the next match.
- If the restriction that failed has a completely blank text box OR it finds a matching general task that does NOT have the "This task can be overridden by other task restriction failures" checkbox selected, then ADRIFT tries to execute this new task.
- If the restriction that failed contains text AND the "This task can be overridden by other task restriction failures" checkbox IS selected on the new task, then ADRIFT will ignore it and continue searching for another match.
- If the restriction that failed contains text, and ADRIFT does not find another task that it can execute, then that text is displayed to the player as a failure message and the player is prompted to enter their next command.
- If the restrictions pass then ADRIFT next checks to see if that general task has any specific tasks that are set to "run before" or "override" it.
- These tasks are checked in priority order.
- If the specific task has had any of its references made specific to a particular item, then that must be the item specified by the player, otherwise it is ignored.
- All of the restrictions of the specific task must pass, otherwise the same steps specified in section 7 above for general tasks are performed for the specific tasks.
- If the specific task matches and passes restrictions then:
- It could itself have specific tasks that override it, so if present we recursivly execute them now.
- If the option "Display completion message Before/After executing actions" on the "Advanced" page of this task is set to "Before", then the text box contents are displayed to the player.
- The task's actions are performed. These can execute other tasks for further processing.
- If "Display completion message Before/After executing actions" is set to "After", then the text box contents are displayed.
- If the specific task that executes has the "Continue executing matching lower priority tasks (multiple matching)" checkbox selected on its "Advanced" page, then ADRIFT continues to check any remaining specific tasks in priority order.
- If there are no "override" tasks, or they fail matching or restrictions, then the text box of the general task is displayed to the player and its actions are performed. If a "run before" task has executed successfully then it controls which parts of the general task execute with its "Display parent message" and "Execute parent actions" check boxes. The order they are done in is controlled by "Display completion message Before/After executing actions" on the general task "Advanced" page.
- ADRIFT next checks to see if that general task has any specific tasks that are set to "Run after" it, and if so, and they match the references and pass restrictions, then they are executed.
- Then ADRIFT checks the "Continue executing matching lower priority tasks (multiple matching)" checkbox on the "Advanced" page of the general task. If this is selected then ADRIFT continues to search lower priority general tasks for another match and goes back to step 4 above if it finds one.
- Finally, any Events that are running are moved forward one turn, which could display text or execute a system task.
|<<< Executing sub-tasks||Main_Page||Characters >>>|