release: Storybook v0.2.0 - Major syntax and features update
BREAKING CHANGES: - Relationship syntax now requires blocks for all participants - Removed self/other perspective blocks from relationships - Replaced 'guard' keyword with 'if' for behavior tree decorators Language Features: - Add tree-sitter grammar with improved if/condition disambiguation - Add comprehensive tutorial and reference documentation - Add SBIR v0.2.0 binary format specification - Add resource linking system for behaviors and schedules - Add year-long schedule patterns (day, season, recurrence) - Add behavior tree enhancements (named nodes, decorators) Documentation: - Complete tutorial series (9 chapters) with baker family examples - Complete reference documentation for all language features - SBIR v0.2.0 specification with binary format details - Added locations and institutions documentation Examples: - Convert all examples to baker family scenario - Add comprehensive working examples Tooling: - Zed extension with LSP integration - Tree-sitter grammar for syntax highlighting - Build scripts and development tools Version Updates: - Main package: 0.1.0 → 0.2.0 - Tree-sitter grammar: 0.1.0 → 0.2.0 - Zed extension: 0.1.0 → 0.2.0 - Storybook editor: 0.1.0 → 0.2.0
This commit is contained in:
417
docs/book/tutorial/05-advanced-behaviors.html
Normal file
417
docs/book/tutorial/05-advanced-behaviors.html
Normal file
@@ -0,0 +1,417 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en" class="light sidebar-visible" dir="ltr">
|
||||
<head>
|
||||
<!-- Book generated using mdBook -->
|
||||
<meta charset="UTF-8">
|
||||
<title>Advanced Behaviors - Storybook Language Guide</title>
|
||||
|
||||
|
||||
<!-- Custom HTML head -->
|
||||
|
||||
<meta name="description" content="Comprehensive documentation for the Storybook narrative simulation language">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="theme-color" content="#ffffff">
|
||||
|
||||
<link rel="icon" href="../favicon.svg">
|
||||
<link rel="shortcut icon" href="../favicon.png">
|
||||
<link rel="stylesheet" href="../css/variables.css">
|
||||
<link rel="stylesheet" href="../css/general.css">
|
||||
<link rel="stylesheet" href="../css/chrome.css">
|
||||
<link rel="stylesheet" href="../css/print.css" media="print">
|
||||
|
||||
<!-- Fonts -->
|
||||
<link rel="stylesheet" href="../FontAwesome/css/font-awesome.css">
|
||||
<link rel="stylesheet" href="../fonts/fonts.css">
|
||||
|
||||
<!-- Highlight.js Stylesheets -->
|
||||
<link rel="stylesheet" href="../highlight.css">
|
||||
<link rel="stylesheet" href="../tomorrow-night.css">
|
||||
<link rel="stylesheet" href="../ayu-highlight.css">
|
||||
|
||||
<!-- Custom theme stylesheets -->
|
||||
|
||||
|
||||
<!-- Provide site root to javascript -->
|
||||
<script>
|
||||
var path_to_root = "../";
|
||||
var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "light";
|
||||
</script>
|
||||
<!-- Start loading toc.js asap -->
|
||||
<script src="../toc.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="body-container">
|
||||
<!-- Work around some values being stored in localStorage wrapped in quotes -->
|
||||
<script>
|
||||
try {
|
||||
var theme = localStorage.getItem('mdbook-theme');
|
||||
var sidebar = localStorage.getItem('mdbook-sidebar');
|
||||
|
||||
if (theme.startsWith('"') && theme.endsWith('"')) {
|
||||
localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
|
||||
}
|
||||
|
||||
if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
|
||||
localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
|
||||
}
|
||||
} catch (e) { }
|
||||
</script>
|
||||
|
||||
<!-- Set the theme before any content is loaded, prevents flash -->
|
||||
<script>
|
||||
var theme;
|
||||
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
|
||||
if (theme === null || theme === undefined) { theme = default_theme; }
|
||||
const html = document.documentElement;
|
||||
html.classList.remove('light')
|
||||
html.classList.add(theme);
|
||||
html.classList.add("js");
|
||||
</script>
|
||||
|
||||
<input type="checkbox" id="sidebar-toggle-anchor" class="hidden">
|
||||
|
||||
<!-- Hide / unhide sidebar before it is displayed -->
|
||||
<script>
|
||||
var sidebar = null;
|
||||
var sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
|
||||
if (document.body.clientWidth >= 1080) {
|
||||
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
|
||||
sidebar = sidebar || 'visible';
|
||||
} else {
|
||||
sidebar = 'hidden';
|
||||
}
|
||||
sidebar_toggle.checked = sidebar === 'visible';
|
||||
html.classList.remove('sidebar-visible');
|
||||
html.classList.add("sidebar-" + sidebar);
|
||||
</script>
|
||||
|
||||
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
|
||||
<!-- populated by js -->
|
||||
<mdbook-sidebar-scrollbox class="sidebar-scrollbox"></mdbook-sidebar-scrollbox>
|
||||
<noscript>
|
||||
<iframe class="sidebar-iframe-outer" src="../toc.html"></iframe>
|
||||
</noscript>
|
||||
<div id="sidebar-resize-handle" class="sidebar-resize-handle">
|
||||
<div class="sidebar-resize-indicator"></div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div id="page-wrapper" class="page-wrapper">
|
||||
|
||||
<div class="page">
|
||||
<div id="menu-bar-hover-placeholder"></div>
|
||||
<div id="menu-bar" class="menu-bar sticky">
|
||||
<div class="left-buttons">
|
||||
<label id="sidebar-toggle" class="icon-button" for="sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
|
||||
<i class="fa fa-bars"></i>
|
||||
</label>
|
||||
<button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
|
||||
<i class="fa fa-paint-brush"></i>
|
||||
</button>
|
||||
<ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
|
||||
<li role="none"><button role="menuitem" class="theme" id="light">Light</button></li>
|
||||
<li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
|
||||
<li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
|
||||
<li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
|
||||
<li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
|
||||
</ul>
|
||||
<button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
|
||||
<i class="fa fa-search"></i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<h1 class="menu-title">Storybook Language Guide</h1>
|
||||
|
||||
<div class="right-buttons">
|
||||
<a href="../print.html" title="Print this book" aria-label="Print this book">
|
||||
<i id="print-button" class="fa fa-print"></i>
|
||||
</a>
|
||||
<a href="https://github.com/r3t-studios/storybook" title="Git repository" aria-label="Git repository">
|
||||
<i id="git-repository-button" class="fa fa-github"></i>
|
||||
</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="search-wrapper" class="hidden">
|
||||
<form id="searchbar-outer" class="searchbar-outer">
|
||||
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
|
||||
</form>
|
||||
<div id="searchresults-outer" class="searchresults-outer hidden">
|
||||
<div id="searchresults-header" class="searchresults-header"></div>
|
||||
<ul id="searchresults">
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
|
||||
<script>
|
||||
document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
|
||||
document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
|
||||
Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
|
||||
link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
|
||||
});
|
||||
</script>
|
||||
|
||||
<div id="content" class="content">
|
||||
<main>
|
||||
<h1 id="advanced-behaviors"><a class="header" href="#advanced-behaviors">Advanced Behaviors</a></h1>
|
||||
<p>You have learned the fundamentals of behavior trees. This chapter covers advanced patterns: complex decision hierarchies, modular design with subtrees, and state-driven behavior.</p>
|
||||
<h2 id="deep-decision-trees"><a class="header" href="#deep-decision-trees">Deep Decision Trees</a></h2>
|
||||
<p>Real characters need layered decision-making. Nest selectors and sequences to create rich AI:</p>
|
||||
<pre><code class="language-storybook">behavior Baker_DailyAI {
|
||||
choose daily_activity {
|
||||
// Morning: Prepare the bakery
|
||||
then morning_prep {
|
||||
if(time_is_morning)
|
||||
then prep_sequence {
|
||||
LightOven
|
||||
PrepareDough
|
||||
StartFirstBatch
|
||||
}
|
||||
}
|
||||
|
||||
// Day: Serve customers
|
||||
then day_service {
|
||||
if(time_is_daytime)
|
||||
choose service_mode {
|
||||
then serve_customer {
|
||||
if(customer_waiting)
|
||||
GreetCustomer
|
||||
TakeOrder
|
||||
PackageItems
|
||||
CollectPayment
|
||||
}
|
||||
|
||||
then restock {
|
||||
if(display_low)
|
||||
FetchFromKitchen
|
||||
}
|
||||
|
||||
CleanCounter
|
||||
}
|
||||
}
|
||||
|
||||
// Evening: Close up
|
||||
then evening_close {
|
||||
if(time_is_evening)
|
||||
then close_sequence {
|
||||
TurnOffOvens
|
||||
CleanKitchen
|
||||
CountRegister
|
||||
LockUp
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<p>Each level of nesting refines the decision. The outer <code>choose</code> selects the time of day; inner nodes handle the specifics.</p>
|
||||
<h2 id="modular-subtrees"><a class="header" href="#modular-subtrees">Modular Subtrees</a></h2>
|
||||
<p>Large behavior trees become unwieldy. Break them into focused subtrees and compose with <code>include</code>:</p>
|
||||
<pre><code class="language-storybook">// Focused subtree: just baking
|
||||
behavior Baking_Sourdough {
|
||||
then sourdough_sequence {
|
||||
MixDough
|
||||
KneadDough
|
||||
FirstRise
|
||||
ShapeLoaves
|
||||
}
|
||||
}
|
||||
|
||||
// Focused subtree: just customer service
|
||||
behavior Service_ServeCustomer {
|
||||
then service_sequence {
|
||||
GreetCustomer
|
||||
TakeOrder
|
||||
PackageItems
|
||||
CollectPayment
|
||||
}
|
||||
}
|
||||
|
||||
// Composition: combine subtrees
|
||||
behavior Martha_FullDay {
|
||||
choose activity {
|
||||
then morning_baking {
|
||||
if(time_is_morning)
|
||||
include Baking_Sourdough
|
||||
include Baking_Pastries
|
||||
}
|
||||
|
||||
then afternoon_sales {
|
||||
if(time_is_afternoon)
|
||||
include Service_ServeCustomer
|
||||
}
|
||||
|
||||
CleanWorkstation
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<p>Benefits of modular subtrees:</p>
|
||||
<ul>
|
||||
<li>Each subtree is testable in isolation</li>
|
||||
<li>Multiple characters can share subtrees</li>
|
||||
<li>Changes propagate automatically</li>
|
||||
</ul>
|
||||
<h2 id="conditional-behavior-selection"><a class="header" href="#conditional-behavior-selection">Conditional Behavior Selection</a></h2>
|
||||
<p>Use conditions to switch between behavioral modes:</p>
|
||||
<pre><code class="language-storybook">behavior SmartBaker {
|
||||
choose strategy {
|
||||
// Busy mode when there are many customers
|
||||
then busy_mode {
|
||||
if(customer_count > 5 and inventory_sufficient)
|
||||
choose rush_tactics {
|
||||
ServeFastOrder
|
||||
QuickRestock
|
||||
ExpressBake
|
||||
}
|
||||
}
|
||||
|
||||
// Careful mode when supplies are low
|
||||
then careful_mode {
|
||||
if(inventory_low or special_ingredients_missing)
|
||||
choose conservation_tactics {
|
||||
ReducePortions
|
||||
SubstituteIngredients
|
||||
OrderEmergencySupply
|
||||
}
|
||||
}
|
||||
|
||||
// Normal mode otherwise
|
||||
then normal_mode {
|
||||
if(customer_count <= 5 and inventory_sufficient)
|
||||
StandardRoutine
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<h2 id="decorator-combinations"><a class="header" href="#decorator-combinations">Decorator Combinations</a></h2>
|
||||
<p>Combine decorators to build sophisticated control patterns:</p>
|
||||
<pre><code class="language-storybook">behavior Baker_SpecialRecipe {
|
||||
// Only when inventory is sufficient
|
||||
if(has_special_ingredients) {
|
||||
// Limited to once per hour
|
||||
cooldown(1h) {
|
||||
// Must complete within 30 minutes
|
||||
timeout(30m) {
|
||||
// Try up to 3 times
|
||||
retry(3) {
|
||||
then bake_special {
|
||||
PrepareSpecialDough
|
||||
BakeAtPreciseTemperature
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<h2 id="prose-documentation"><a class="header" href="#prose-documentation">Prose Documentation</a></h2>
|
||||
<p>Add narrative context to complex behaviors with prose blocks:</p>
|
||||
<pre><code class="language-storybook">behavior Elena_TrainingSession {
|
||||
---description
|
||||
Elena practicing a new recipe under Martha's guidance.
|
||||
Uses retry decorator for persistence and if for
|
||||
checking readiness.
|
||||
---
|
||||
|
||||
choose training_strategy {
|
||||
then practice_supervised {
|
||||
if(martha_available)
|
||||
retry(3) {
|
||||
then attempt_recipe {
|
||||
ReviewRecipeSteps
|
||||
MeasureIngredients
|
||||
MixAndKnead
|
||||
CheckWithMartha
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
then practice_solo {
|
||||
if(not martha_available)
|
||||
then solo_attempt {
|
||||
ReviewRecipeNotes
|
||||
AttemptRecipeFromMemory
|
||||
TasteTestResult
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<h2 id="design-tips"><a class="header" href="#design-tips">Design Tips</a></h2>
|
||||
<p><strong>Prefer shallow trees</strong>: Break deep nesting into subtrees with <code>include</code>.</p>
|
||||
<p><strong>Name every composite node</strong>: Labels make trees self-documenting.</p>
|
||||
<p><strong>Use decorators for control flow</strong>: Timing, repetition, and gating belong in decorators, not in action logic.</p>
|
||||
<p><strong>Keep actions atomic</strong>: Each action should do one thing. Complex operations are sequences of simple actions.</p>
|
||||
<h2 id="next-steps"><a class="header" href="#next-steps">Next Steps</a></h2>
|
||||
<p>Characters do not exist in isolation. In <a href="./06-relationships.html">Character Relationships</a>, you will model how characters connect to each other – friendships, rivalries, parent-child bonds, and more.</p>
|
||||
<hr />
|
||||
<p><strong>Reference</strong>: See <a href="../reference/11-behavior-trees.html">Behavior Trees Reference</a> and <a href="../reference/12-decorators.html">Decorators Reference</a> for complete syntax.</p>
|
||||
|
||||
</main>
|
||||
|
||||
<nav class="nav-wrapper" aria-label="Page navigation">
|
||||
<!-- Mobile navigation buttons -->
|
||||
<a rel="prev" href="../tutorial/04-making-characters-act.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
<a rel="next prefetch" href="../tutorial/06-relationships.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
|
||||
<div style="clear: both"></div>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<nav class="nav-wide-wrapper" aria-label="Page navigation">
|
||||
<a rel="prev" href="../tutorial/04-making-characters-act.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
<a rel="next prefetch" href="../tutorial/06-relationships.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
||||
<i class="fa fa-angle-right"></i>
|
||||
</a>
|
||||
</nav>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Livereload script (if served using the cli tool) -->
|
||||
<script>
|
||||
const wsProtocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
const wsAddress = wsProtocol + "//" + location.host + "/" + "__livereload";
|
||||
const socket = new WebSocket(wsAddress);
|
||||
socket.onmessage = function (event) {
|
||||
if (event.data === "reload") {
|
||||
socket.close();
|
||||
location.reload();
|
||||
}
|
||||
};
|
||||
|
||||
window.onbeforeunload = function() {
|
||||
socket.close();
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
window.playground_copyable = true;
|
||||
</script>
|
||||
|
||||
|
||||
<script src="../elasticlunr.min.js"></script>
|
||||
<script src="../mark.min.js"></script>
|
||||
<script src="../searcher.js"></script>
|
||||
|
||||
<script src="../clipboard.min.js"></script>
|
||||
<script src="../highlight.js"></script>
|
||||
<script src="../book.js"></script>
|
||||
|
||||
<!-- Custom JS scripts -->
|
||||
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user