Scripting
Complete and Control Progression
Complete the active Objective, select a Chapter, step back, and react to rejected calls through public results.
Complete only the active exact Objective
External code can read manager.CurrentChapter and call chapter.TryCompleteObjective(manager.CurrentObjectiveId). The method returns false when the Chapter is not Active, the row is missing or non-Active, or the supplied ID differs by any character. A successful call runs the normal lifecycle, persistence, audio, and advance behavior.
Pass runCompletionActions: false only when intentionally marking the current row Skipped. It does not mean “complete silently”; it chooses a different terminal state and omits completion actions.
Select a Chapter deliberately
TrySelectChapter(string) matches an exact stable ID and performs a fresh Chapter start. SelectChapter(int) uses the configured array index and logs an error for an invalid index. Selecting another Chapter disables the previous Chapter GameObject, enables the target, resets the target's known progress, and begins its flow.
Use stable IDs for menus and integrations; array indices can change during authoring. Do not confuse selection with persisted scene handoff: direct selection acts in the current scene, whereas TransitionToScene carries a one-use target to another scene.
Move back one position
Chapter.TryStepBack(currentObjectiveId) requires the exact current ID and a previous array position. It returns false at the first row, in a non-Active Chapter, or for stale identity. On success it completes the current row with step-back semantics, resets the previous record and linked physical Objective, and starts the previous position.
Step-back does not reconstruct arbitrary world changes or erase all later persistence. Build explicit reverse actions for moved, destroyed, or externally owned content.
Treat return values as part of control flow
| Command | Result | Caller action |
|---|---|---|
| TryCompleteObjective | bool | Show accepted feedback only on true |
| TrySelectChapter | bool | Handle an unknown ID without assuming selection |
| TryStepBack | bool | Disable Back UI when false is expected |
| TryFailCurrentChapter | ChapterFailureResult | Distinguish not ready, no active Chapter, terminal state, and transition lock |
| Progress commands | ProgressOperationResult | Report backend/configuration failure separately from gameplay success |
Complete the active Objective from external code
- Where to place it
- Add this component to the GameObject that owns the external gameplay signal.
- When to call it
- Call TryCompleteCurrentObjective from a validated interaction, dialogue callback or project event.
- Behavior
- The method never searches by a partial ID and returns false when the Manager, Chapter or active Objective is missing.
using System;
using System.Collections;
using System.Collections.Generic;
using OverFuture.ChapterObjectiveSystem.Chapters;
using OverFuture.ChapterObjectiveSystem.Events;
using OverFuture.ChapterObjectiveSystem.Objectives;
using OverFuture.ChapterObjectiveSystem.Persistence;
using OverFuture.ChapterObjectiveSystem.Progression;
using UnityEngine;
public sealed class ExternalObjectiveCompletionExample : MonoBehaviour
{
public bool TryCompleteCurrentObjective()
{
ChapterManager manager = ChapterManager.Instance;
Chapter chapter = manager != null ? manager.CurrentChapter : null;
if (chapter == null || !manager.HasActiveObjective)
{
return false;
}
return chapter.TryCompleteObjective(manager.CurrentObjectiveId);
}
}
Move back one ordered position
- Where to place it
- Add this component to the UI or system that owns a deliberate Back action.
- When to call it
- Call TryReturnToPreviousObjective while the Chapter and current Objective are active.
- Behavior
- TryStepBack requires an exact current ID and at least one previous entry. It is not an arbitrary history stack.
using System;
using System.Collections;
using System.Collections.Generic;
using OverFuture.ChapterObjectiveSystem.Chapters;
using OverFuture.ChapterObjectiveSystem.Events;
using OverFuture.ChapterObjectiveSystem.Objectives;
using OverFuture.ChapterObjectiveSystem.Persistence;
using OverFuture.ChapterObjectiveSystem.Progression;
using UnityEngine;
public sealed class StepBackExample : MonoBehaviour
{
public bool TryReturnToPreviousObjective()
{
ChapterManager manager = ChapterManager.Instance;
Chapter chapter = manager != null ? manager.CurrentChapter : null;
return chapter != null && manager.HasActiveObjective &&
chapter.TryStepBack(manager.CurrentObjectiveId);
}
}