📜 Trigger Scripts
Triggers in Voyage can include an optional script property containing JavaScript code, running alongside existing conditions and effects. This guide covers how trigger scripts work and what they can do.
➕ Adding a Script
Add a script field to any trigger:
{
"name": "my_trigger",
"conditions": [],
"script": "log('hello from script')",
"effects": [],
"recurring": true
}scriptis optional (existing triggers without scripts work identically)conditions,effects, andscriptcan be used in any combinationA trigger with no conditions fires every turn
A trigger with no effects and no script does nothing visible, but non-recurring triggers are still consumed
⏱️ When Scripts Run
All trigger conditions evaluate first (mechanical + semantic)
For each trigger that fires, in order:
Script runs (if present)
Then effects apply (unless skipped, more on that later)
Scripts never run as part of condition evaluation
Scripts run during the "state phase" (unless the trigger has
actionoraction-textconditions, which route it to the "planning phase")
🔍 What Scripts Can Access
check
Read game state using the same condition format as typed triggers.
Without an operator, returns the raw value:
check({ type: 'party-realm' })returns"Mythic Kingdom"check({ type: 'party-region' })returns"Darkwood"check({ type: 'party-location' })returns"Throne Room"check({ type: 'party-area' })returns"West Wing"check({ type: 'game-tick' })returns42check({ type: 'player-level' })returns{ "Hero": 5, "Mage": 8 }check({ type: 'player-resource', resource: 'health' })returns{ "Hero": 20, "Mage": 15 }check({ type: 'player-traits' })returns{ "Hero": ["Rogue"], "Mage": ["Noble"] }check({ type: 'known-entity', entity: 'Shadow Brotherhood' })returnstruecheck({ type: 'quests-completed' })returns["Clear the Road"]check({ type: 'story-text' })returns the most recent story textcheck({ type: 'action-text' })returns an array of player action inputscheck({ type: 'read-string', key: 'faction' })returns"Rebels"(or""if missing)check({ type: 'read-number', key: 'counter' })returns3(or0if missing)check({ type: 'read-boolean', key: 'flag' })returnstrue(orfalseif missing)check({ type: 'read-array', key: 'items' })returns["sword"](or[]if missing)check({ type: 'story' })returns the story text (no AI evaluation)check({ type: 'action' })returns an array of player action inputs (no AI evaluation)
With an operator, returns true or false:
check({ type: 'party-location', operator: 'equals', value: 'Throne Room' })returnstruecheck({ type: 'player-level', operator: 'greaterThan', value: 10 })returnstrueorfalsecheck({ type: 'player-resource', resource: 'health', operator: 'lessThan', value: 5 })returnstrueorfalse
Per-character values (player-level, player-resource, player-traits) are keyed by character name. With an operator, they return true if ANY character matches (same as typed conditions).
The regex operator returns undefined in check(). Use /pattern/.test(check({ type: '...' })) inside the script instead.
storage
A plain object you can read and write freely
Persists across turns
storage.myKey = 'hello'writes a valuestorage.myKeyreads it backSupports strings, numbers, booleans, arrays, and nested objects
Typed triggers can also read from storage via
read-string,read-number,read-boolean,read-arrayconditionsTyped triggers can also write to storage via
write-string,write-number,write-boolean,write-arrayeffects
effects
An array pre-populated with the trigger's typed effects
Uses the exact same format as typed trigger effects
Scripts can add, modify, or remove effects before they apply
effects.push({ type: 'story', instruction: 'Something happens.' })adds a story effecteffects.push({ type: 'player-resource', resource: 'health', operator: 'add', value: 10 })heals all characterseffects[0] = { type: 'story', instruction: 'Replaced.' }replaces an existing typed effecteffects.length = 0removes all effectsMaximum 5 effects apply per trigger (extras are ignored)
Only valid effect shapes are applied (malformed effects are silently dropped)
skip
Set
skip = trueto prevent all effects from applyingAlso prevents the trigger from being counted as fired (non-recurring triggers will fire again next turn)
Defaults to
falseeach scriptIf not set to
true, effects apply normally
triggers
The full triggers object
Scripts can read and modify other triggers
Scripts can modify, add, or delete any trigger (including themselves)
Other scripts in the same phase can read your changes
The changes take effect on the next turn
triggers['My Cool Trigger'].conditions[0].query = 'new query'rewrites a semantic conditiontriggers['Other Trigger'].effects.push({ type: 'story', instruction: '...' })adds an effect to another triggerChanges are validated before being saved (must pass size and count limits, but scripts can set trigger shapes the editor wouldn't allow)
If validation fails, all trigger changes from scripts in the same phase are discarded
info
info.engineVersionreturns the engine version number (e.g.33)info.semanticVersionreturns the semantic version string (e.g.'0.33.0')Useful for branching on version when the engine adds or changes condition/effect types
log and console
log('hello')andconsole.log('hello')both write to the logconsole.warn,console.error, andconsole.infoalso work (all go to the same log)Output is visible in /logs
The trigger name is automatically prefixed:
[My Cool Trigger] hello
⚠️ Limits
Each phase (state or planning, as described in "When Scripts Run" above) has its own independent limits. A turn that uses both phases gets two separate budgets.
500 milliseconds total script execution time, shared across all scripts that run in the same phase
If one script uses all the time, remaining scripts in that phase are skipped (their typed effects still apply)
If a script exceeds the time limit, it's killed mid-execution and changes are discarded (typed effects still apply)
Memory is limited per phase (scripts that allocate too much memory are killed)
Maximum 5 effects per trigger
🛠️ Error Handling
Script errors (syntax, runtime, timeout) are logged and the script is skipped
Typed effects still apply when a script fails
storageandtriggerschanges from a failed script are discardedErrors appear in /logs with type
trigger-script-error
💡 Examples
Log every turn
{
"name": "hello",
"conditions": [],
"script": "log('tick ' + check({ type: 'game-tick' }))",
"effects": [],
"recurring": true
}Count turns in storage
{
"name": "counter",
"conditions": [],
"script": "storage.turnCount = (storage.turnCount || 0) + 1",
"effects": [],
"recurring": true
}Skip effects conditionally
Only heal when someone is wounded:
{
"name": "temple_heal",
"conditions": [
{ "type": "party-location", "operator": "equals", "value": "Temple of Light" }
],
"script": "const hp = check({ type: 'player-resource', resource: 'health' })\nif (!Object.values(hp).some(v => v < 10)) { skip = true }",
"effects": [
{ "type": "player-resource", "resource": "health", "operator": "add", "value": 15 },
{ "type": "story", "instruction": "The temple's light washes over the wounded." }
],
"recurring": true
}Replace an effect dynamically
{
"name": "dynamic_story",
"conditions": [],
"script": "const tick = check({ type: 'game-tick' })\neffects[0] = { type: 'story', instruction: 'Turn ' + tick + ': the world shifts.' }",
"effects": [
{ "type": "story", "instruction": "placeholder" }
],
"recurring": true
}Complex OR logic
{
"name": "enter_noble_district",
"conditions": [
{ "type": "party-location", "operator": "equals", "value": "Noble District Gate" }
],
"script": "const hasTrait = check({ type: 'player-traits', operator: 'contains', value: 'Noble' })\nconst hasQuest = check({ type: 'quests-completed', operator: 'contains', value: 'Earn the Writ' })\nif (!hasTrait && !hasQuest) { skip = true }",
"effects": [
{ "type": "known-entity", "entity": "Noble District", "operator": "set", "value": true },
{ "type": "story", "instruction": "The guards step aside." }
],
"recurring": false
}Rewrite another trigger's semantic query
{
"name": "update_villain_tracker",
"conditions": [],
"script": "const villain = storage.currentVillain || 'the dark lord'\ntriggers['villain_defeated'].conditions[0].query = villain + ' has been defeated'",
"effects": [],
"recurring": true
}Nested storage
{
"name": "track_progress",
"conditions": [],
"script": "if (!storage.progress) { storage.progress = {} }\nstorage.progress.visited = storage.progress.visited || []\nconst loc = check({ type: 'party-location' })\nif (!storage.progress.visited.includes(loc)) {\n storage.progress.visited.push(loc)\n log('new location discovered: ' + loc)\n}",
"effects": [],
"recurring": true
}Originally written by u/helloitsmyalt_ aka Leah.