[
{
"url": "/posts/blocks",
"title": "Blocks and States",
"content": "<h1 id=\"blocks-and-states\">Blocks and States</h1><p>The core foundation of Storymatic is the block and state system.</p><h2 id=\"overview\">Overview</h2><p>A block is a collection of statements to run and text to output. <code class=\"language-plaintext highlighter-rouge\">State</code> is an alternative name for <code class=\"language-plaintext highlighter-rouge\">block</code>, but it is usually used to describe the names of blocks, and the internal state that the program is in, while <code class=\"language-plaintext highlighter-rouge\">block</code> is used to describe the statements inside.</p><h2 id=\"example\">Example</h2><pre><code class=\"language-storymatic\">start Hello Bob! What would you like to do today?</code></pre><p>The first line (<code class=\"language-plaintext highlighter-rouge\">start</code>) is the state (name). A state can only contain letters, numbers, and underscores, and must have no indentation.The indented text (<code class=\"language-plaintext highlighter-rouge\">Hello $name...</code>) is the block (content). A block must be indented. The block can have several lines, but they must all be indented.</p><p>The part of the story that contains the states and blocks is called the <code class=\"language-plaintext highlighter-rouge\">root section</code>, or the <code class=\"language-plaintext highlighter-rouge\">root</code>.</p><p><strong>The root should always contain a state called <code class=\"language-plaintext highlighter-rouge\">start</code>, which is where your story should start.</strong></p><h2 id=\"more-examples\">More Examples</h2><p>Here is another example with two states (<code class=\"language-plaintext highlighter-rouge\">chocolate</code> and <code class=\"language-plaintext highlighter-rouge\">vanilla</code>):</p><pre><code class=\"language-storymatic\">chocolate Wow! Chocolate is also my favorite ice cream flavor! Would you like to buy some?vanilla I also love vanilla!</code></pre><p>Notice how both states have no indentation, while the blocks have indentation.</p><p>You can have different levels of indentation for different blocks; thus, this example is valid Storymatic code:</p><pre><code class=\"language-storymatic\">chocolate Wow! Chocolate is also my favorite ice cream flavor! Would you like to buy some?vanilla I also love vanilla!</code></pre>",
"group": "Basics",
"keyword": " blocks"
},
{
"url": "/posts/boolean",
"title": "Boolean Expressions",
"content": "<h1 id=\"boolean-expressions\">Boolean Expressions</h1><p>This article explains what boolean expressions are and how to write them.</p><h2 id=\"overview\">Overview</h2><p>A boolean expression is something that evaluates to <code class=\"language-plaintext highlighter-rouge\">true</code> or <code class=\"language-plaintext highlighter-rouge\">false</code>. You always write them in this format: <code class=\"language-plaintext highlighter-rouge\">${varname} {operator} {value}</code>.</p><p>The <code class=\"language-plaintext highlighter-rouge\">operator</code> can be <code class=\"language-plaintext highlighter-rouge\"><</code>, <code class=\"language-plaintext highlighter-rouge\">></code>, <code class=\"language-plaintext highlighter-rouge\"><=</code>. <code class=\"language-plaintext highlighter-rouge\">>=</code>, <code class=\"language-plaintext highlighter-rouge\">=</code>, or <code class=\"language-plaintext highlighter-rouge\">!=</code>. <code class=\"language-plaintext highlighter-rouge\">!=</code> means “doesn’t equal”.If <code class=\"language-plaintext highlighter-rouge\">operator</code> is <code class=\"language-plaintext highlighter-rouge\"><</code>, <code class=\"language-plaintext highlighter-rouge\">></code>, <code class=\"language-plaintext highlighter-rouge\"><=</code>, or <code class=\"language-plaintext highlighter-rouge\">>=</code>, then <code class=\"language-plaintext highlighter-rouge\">value</code> must be a number.</p><h2 id=\"examples\">Examples</h2><div class=\"language-plaintext highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>$money > 500$money <= 800</code></pre></div></div><p>In the first example, we are checking whether the <code class=\"language-plaintext highlighter-rouge\">money</code> variable is less than <code class=\"language-plaintext highlighter-rouge\">500</code>.In the second example, we are checking whether the <code class=\"language-plaintext highlighter-rouge\">money</code> variable is greater than or equal to <code class=\"language-plaintext highlighter-rouge\">800</code>.</p><h2 id=\"advanced-expressions\">Advanced Expressions</h2><p>You can also join together several simple conditions with <code class=\"language-plaintext highlighter-rouge\">and</code>, <code class=\"language-plaintext highlighter-rouge\">or</code>, and <code class=\"language-plaintext highlighter-rouge\">not</code>.In advanced expressions, <code class=\"language-plaintext highlighter-rouge\">not</code> has higher precedence than <code class=\"language-plaintext highlighter-rouge\">and</code>, which has higher precedence than <code class=\"language-plaintext highlighter-rouge\">or</code>, meaning <code class=\"language-plaintext highlighter-rouge\">not</code> is evaluated before <code class=\"language-plaintext highlighter-rouge\">and</code>, and <code class=\"language-plaintext highlighter-rouge\">and</code> is evaluated before <code class=\"language-plaintext highlighter-rouge\">or</code>.</p><p>For example, you can check whether <code class=\"language-plaintext highlighter-rouge\">money</code> is between 300 and 800 with <code class=\"language-plaintext highlighter-rouge\">$money > 300 and $money < 800</code>.Note that <code class=\"language-plaintext highlighter-rouge\">300 < $money and $money < 800</code> will always evaluate to <code class=\"language-plaintext highlighter-rouge\">false</code> because the variable should come before the value.</p><h2 id=\"usage\">Usage</h2><p>Booleans are used in <a href=\"if-block\">if blocks</a>, <a href=\"for-loop\">for loops</a>, <a href=\"while-loop\">while loops</a>, and <a href=\"while-loop\">do-while loops</a>.</p>",
"group": "Flow",
"keyword": " boolean"
},
{
"url": "/posts/context",
"title": "Contexts",
"content": "<h1 id=\"contexts\">Contexts</h1><p>This article explains how to use contexts.</p><h2 id=\"overview\">Overview</h2><p>A context is a clone of the current story with all local variables reset, but keeping all global variables.You can run statements in a different context by writing <code class=\"language-plaintext highlighter-rouge\">@context</code> and putting statements inside the <code class=\"language-plaintext highlighter-rouge\">@context</code> command.</p><h2 id=\"example\">Example</h2><pre><code class=\"language-storymatic\">@global $money = 500$name = Stevestart $name = Annie $money = 700 name: $name, money: $money @context name: $name, money: $money</code></pre><p>should output</p><div class=\"language-plaintext highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>name: Annie, money: 700name: Steve, money: 700</code></pre></div></div><p>because name is local, but money is global.</p>",
"group": "Flow",
"keyword": " context"
},
{
"url": "/posts/exit",
"title": "Stop and Kill",
"content": "<h1 id=\"stop-and-kill\">Stop and Kill</h1><p>The <code class=\"language-plaintext highlighter-rouge\">stop</code> and <code class=\"language-plaintext highlighter-rouge\">kill</code> statements are key to using the block system.</p><h2 id=\"overview\">Overview</h2><p>The <code class=\"language-plaintext highlighter-rouge\">@stop</code> statement exits the current context. To use it, just write <code class=\"language-plaintext highlighter-rouge\">@stop</code>.The <code class=\"language-plaintext highlighter-rouge\">@kill</code> statement exits the current story (all contexts). TO use it, just write <code class=\"language-plaintext highlighter-rouge\">@kill</code>.</p><h2 id=\"example\">Example</h2><pre><code class=\"language-storymatic\">start Welcome to my text adventure! @menu Do you want to leave? Yes @stop No @pass Goodbye!</code></pre><p>In the example above, the user can exit early by selecting Yes.</p>",
"group": "Flow",
"keyword": " exit"
},
{
"url": "/posts/for-loop",
"title": "For Loops",
"content": "<h1 id=\"for-loops\">For Loops</h1><p>This article explains how to use for loops, which are a shortened and more advanced version of <a href=\"while-loop\">while loops</a>.</p><h2 id=\"overview\">Overview</h2><p>Remember <a href=\"while-loop\">while loops</a>? What if we want to increment a variable each time? We could do:</p><pre><code class=\"language-storymatic\">start $i = 0 @while $i < 5 @nowait $i $i++</code></pre><p>or we could use a <code class=\"language-plaintext highlighter-rouge\">for</code> loop.</p><p>A for loop runs a declaration, and repeats some statements while a condition is true. Each time the statements inside are run, an increment is run.</p><p>You write <code class=\"language-plaintext highlighter-rouge\">@for {declaration};{condition};{increment}</code> and then put statements inside. The first example above could be rewritten with for loops like this:</p><div class=\"language-plaintext highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>start @for $i = 0; $i < 5; $i++ @nowait $i</code></pre></div></div><p>Note that there is no type of for loop that acts like a do-while loop.</p>",
"group": "Loops",
"keyword": " for-loop"
},
{
"url": "/posts/goto-run",
"title": "@goto and @run",
"content": "<h1 id=\"goto-and-run\">@goto and @run</h1><p>By helping keep your story neat, and opening up more possibilites, <code class=\"language-plaintext highlighter-rouge\">@goto</code> and <code class=\"language-plaintext highlighter-rouge\">@run</code> are essential parts of Storymatic.</p><h2 id=\"overview\">Overview</h2><p>Both <code class=\"language-plaintext highlighter-rouge\">@goto</code> and <code class=\"language-plaintext highlighter-rouge\">@run</code> help you transition between blocks. There is a slight difference, which is that <code class=\"language-plaintext highlighter-rouge\">@goto</code> goes to a block and exits the current one, while <code class=\"language-plaintext highlighter-rouge\">@run</code> goes to a block, and when stopped, continues the current one.</p><p>You write them like this:</p><div class=\"language-plaintext highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>@goto {blockname}@run {blockname}</code></pre></div></div><h2 id=\"example\">Example</h2><p>Remember our example from <a href=\"menu\"><code class=\"language-plaintext highlighter-rouge\">@menu</code></a>? We can improve this by using seperate blocks.</p><pre><code class=\"language-storymatic\">start Welcome to the ice cream store! @menu What flavor would you like to buy? Chocolate @goto chocolate Vanilla You bought vanilla! Strawberry You bought strawberry! Goodbye!chocolate @menu Would you like milk or dark chocolate? Dark Chocolate You bought dark chocolate! Milk Chocolate You bought milk chocolate!</code></pre><p>In the example above, if the user selects <code class=\"language-plaintext highlighter-rouge\">Chocolate</code>, we go to the state <code class=\"language-plaintext highlighter-rouge\">chocolate</code>.</p><h2 id=\"goto-vs-run\">Goto vs. Run</h2><p>In the example above, the user will not see <code class=\"language-plaintext highlighter-rouge\">Goodbye!</code> if they selected <code class=\"language-plaintext highlighter-rouge\">Chocolate</code> because we used <code class=\"language-plaintext highlighter-rouge\">goto</code>, meaning that when the <code class=\"language-plaintext highlighter-rouge\">chocolate</code> state ends, the story will end.However, in</p><pre><code class=\"language-storymatic\">start Welcome to the ice cream store! @menu What flavor would you like to buy? Chocolate @run chocolate Vanilla You bought vanilla! Strawberry You bought strawberry! Goodbye!chocolate @menu Would you like milk or dark chocolate? Dark Chocolate You bought dark chocolate! Milk Chocolate You bought milk chocolate!</code></pre><p>we use <code class=\"language-plaintext highlighter-rouge\">@run</code>, so when the <code class=\"language-plaintext highlighter-rouge\">chocolate</code> state ends, it will continue the current state, meaning it will show <code class=\"language-plaintext highlighter-rouge\">Goodbye!</code>.</p>",
"group": "Flow",
"keyword": " goto-run"
},
{
"url": "/posts/if-block",
"title": "If, Else, and Elseif",
"content": "<h1 id=\"if-else-and-elseif\">If, Else, and Elseif</h1><p>As the most common use of <a href=\"boolean\">booleans</a>, if blocks are a quick and easy way to check if a boolean expression is <code class=\"language-plaintext highlighter-rouge\">true</code>.</p><h2 id=\"overview\">Overview</h2><p>If blocks run statements inside if a boolean expression is <code class=\"language-plaintext highlighter-rouge\">true</code>. You begin by writing <code class=\"language-plaintext highlighter-rouge\">@if {condition}</code>, and then put statements inside.</p><h2 id=\"example\">Example</h2><pre><code class=\"language-storymatic\">$money = 300start @if $money < 500 You have less than $500.</code></pre><h2 id=\"else\">@else</h2><p>You can also specify statements to run if the condition is <code class=\"language-plaintext highlighter-rouge\">false</code>.You do this by typing <code class=\"language-plaintext highlighter-rouge\">@else</code> at the same level of indentation that your <code class=\"language-plaintext highlighter-rouge\">@if</code> had, and putting statements inside it.</p><pre><code class=\"language-storymatic\">$money = 300start @if $money < 500 You have less than $500. @else You do not have less than $500.</code></pre><p>Using nested <code class=\"language-plaintext highlighter-rouge\">@if</code>s with <code class=\"language-plaintext highlighter-rouge\">@else</code>, you can do several <code class=\"language-plaintext highlighter-rouge\">@if</code> clauses:</p><pre><code class=\"language-storymatic\">$money = 300start @if $money < 500 You have less than $500. @else @if $money < 1000 You have less than $1000. @else @if $money < 2000 You have less than $2000. @else You do not have less than $2000.</code></pre><p>However, this can get a bit messy, so let’s learn about <code class=\"language-plaintext highlighter-rouge\">@elseif</code>.</p><h2 id=\"elseif\">@elseif</h2><p><code class=\"language-plaintext highlighter-rouge\">@elseif</code> is an alternative method to using nested <code class=\"language-plaintext highlighter-rouge\">@if</code>s. You use it similar to <code class=\"language-plaintext highlighter-rouge\">@if</code>, but it must follow an <code class=\"language-plaintext highlighter-rouge\">@if</code> or <code class=\"language-plaintext highlighter-rouge\">@elseif</code> statement.You can always put <code class=\"language-plaintext highlighter-rouge\">@else</code> after a group of <code class=\"language-plaintext highlighter-rouge\">@elseif</code>s or one <code class=\"language-plaintext highlighter-rouge\">@elseif</code>.</p><p>Here’s the example from above, written using <code class=\"language-plaintext highlighter-rouge\">@elseif</code>:</p><pre><code class=\"language-storymatic\">$money = 300start @if $money < 500 You have less than $500. @elseif $money < 1000 You have less than $1000. @elseif $money < 2000 You have less than $2000. @else You do not have less than $2000.</code></pre>",
"group": "Flow",
"keyword": " if-block"
},
{
"url": "/posts/input",
"title": "Inputs",
"content": "<h1 id=\"inputs\">Inputs</h1><p>You can ask the user to type a custom value for a variable. This article explains how.</p><h2 id=\"asking-for-text\">Asking for Text</h2><p>To input for text, use <code class=\"language-plaintext highlighter-rouge\">${varname} = @input</code>. You can optionally provide a question.</p><pre><code class=\"language-storymatic\">start $name = @input What is your name? Hi, $name!</code></pre><h2 id=\"asking-for-numbers\">Asking for Numbers</h2><p>To input for a number, use <code class=\"language-plaintext highlighter-rouge\">${varname} = @number</code>. You can optionally provide a question.</p><pre><code class=\"language-storymatic\">start $name = @input What is your name? $money = @number How much money do you have? Hi, $name! You have $$money.</code></pre>",
"group": "Variables, Input",
"keyword": " input"
},
{
"url": "/posts/menu",
"title": "Menus",
"content": "<h1 id=\"menus\">Menus</h1><p>This article explains how to ask the user to choose between several options.</p><h2 id=\"overview\">Overview</h2><p>A menu has several options, and different statements will run depending on which option the user selects. For example, you might want to ask the user what their favorite flavor of ice cream is.</p><p>A menu starts with the <code class=\"language-plaintext highlighter-rouge\">@menu</code> command, which can optionally have a question provided. Inside the <code class=\"language-plaintext highlighter-rouge\">@menu</code> command, there must be a list of options, all indented. Each option must also have some statemants inside.</p><h2 id=\"example\">Example</h2><pre><code class=\"language-storymatic\">start Welcome to the ice cream store! @menu What flavor would you like to buy? Chocolate You bought chocolate! Vanilla You bought vanilla! Strawberry You bought strawberry!</code></pre><p>In the above example, a menu will run with the options <code class=\"language-plaintext highlighter-rouge\">Chocolate</code>, <code class=\"language-plaintext highlighter-rouge\">Vanilla</code>, and <code class=\"language-plaintext highlighter-rouge\">Strawberry</code>, and depending on which item you select, the program will say which flavor you bought!</p><p>Note that menus can have more than one statement inside each option, and can even have sub-menus, which this example uses:</p><pre><code class=\"language-storymatic\">start Welcome to the ice cream store! @menu What flavor would you like to buy? Chocolate @menu Would you like milk or dark chocolate? Dark Chocolate You bought dark chocolate! Milk Chocolate You bought milk chocolate! Vanilla You bought vanilla! Strawberry You bought strawberry!</code></pre>",
"group": "Input",
"keyword": " menu"
},
{
"url": "/posts/raw",
"title": "Raw Text, @pass, and @base",
"content": "<h1 id=\"raw-text-pass-and-base\">Raw Text, @pass, and @base</h1><p>This article explains how to print raw text without “evaluating” it.</p><h2 id=\"overview\">Overview</h2><p>You can put a space before text to force it to be raw:</p><pre><code class=\"language-storymatic\">$money = 500start This line will print the value of $money. This line will actually print $money.</code></pre><p>The above example should print:</p><div class=\"language-plaintext highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code>This line will print the value of 500.This line will actually print $money.</code></pre></div></div><p>The problem is when you put a space before each line, because then the level of indentation changes, and all of your statements are now non-raw. How do we fix this?</p><h2 id=\"base\">@base</h2><p>We can fix it by putting a line that prints nothing as the first line, such as <code class=\"language-plaintext highlighter-rouge\">$var = for indent</code>.However, this is a messy way to do it, so we need a statement that does nothing. Meet <code class=\"language-plaintext highlighter-rouge\">@base</code>!</p><p><code class=\"language-plaintext highlighter-rouge\">@base</code> on a line by itself will literally do nothing, but it can help place the indentation level:</p><pre><code class=\"language-storymatic\">$money = 500start @base This line will print $money. This line will also print $money.</code></pre><h2 id=\"pass\">@pass</h2><p>There is a second statement like <code class=\"language-plaintext highlighter-rouge\">@base</code>: <code class=\"language-plaintext highlighter-rouge\">@pass</code>. <code class=\"language-plaintext highlighter-rouge\">@pass</code> also does nothing.</p><h2 id=\"base-vs-pass\">@base vs. @pass</h2><p>@base is meant to be used to set the level of indentation, while <code class=\"language-plaintext highlighter-rouge\">@pass</code> is meant to aid in creating blank blocks, such as a blank option inside an <code class=\"language-plaintext highlighter-rouge\">@menu</code> block.They can be used interchangeably, but please respect their semantic meanings.</p>",
"group": "Basics",
"keyword": " raw"
},
{
"url": "/posts/repeat-loop",
"title": "The Repeat Loop",
"content": "<h1 id=\"the-repeat-loop\">The Repeat Loop</h1><p>The article explains how to use the most basic loop, the repeat loop, which repeats some statements a specified number of times.</p><h2 id=\"overview\">Overview</h2><p>You write <code class=\"language-plaintext highlighter-rouge\">@repeat {number}</code> and put statements inside to use it. <code class=\"language-plaintext highlighter-rouge\">number</code> must be a whole number between <code class=\"language-plaintext highlighter-rouge\">1</code> and <code class=\"language-plaintext highlighter-rouge\">99</code>.</p><h2 id=\"example\">Example</h2><pre><code class=\"language-storymatic\">$money = 0start @repeat 5 $money += 500 @nowait $money</code></pre><p>The above example will increment <code class=\"language-plaintext highlighter-rouge\">money</code> by <code class=\"language-plaintext highlighter-rouge\">500</code> <code class=\"language-plaintext highlighter-rouge\">5</code> times.</p>",
"group": "Loops",
"keyword": " repeat-loop"
},
{
"url": "/posts/story",
"title": "Storymatic",
"content": "<h1 id=\"storymatic\">Storymatic</h1><ul> <li><a href=\"#story-object\"><code class=\"language-plaintext highlighter-rouge\">story</code> Object</a></li> <li><a href=\"#story-static-methods\"><code class=\"language-plaintext highlighter-rouge\">story</code> Static Methods</a></li></ul><h2 id=\"story-object\"><code class=\"language-plaintext highlighter-rouge\">story</code> Object</h2><p>To create a new <code class=\"language-plaintext highlighter-rouge\">story</code> object, initialize it with <code class=\"language-plaintext highlighter-rouge\">story(code)</code>. The <code class=\"language-plaintext highlighter-rouge\">code</code> should be the source code for your story.</p><h3 id=\"state\"><code class=\"language-plaintext highlighter-rouge\">.state</code></h3><p>This is the current state (block name) that the story is in.</p><h3 id=\"states\"><code class=\"language-plaintext highlighter-rouge\">.states</code></h3><p>This is a dictionary of all the different states and their blocks.</p><h3 id=\"localvars\"><code class=\"language-plaintext highlighter-rouge\">.localVars</code></h3><p>This is a dictionary of all the local variables (variables that get reset with <code class=\"language-plaintext highlighter-rouge\">.newContext()</code>).</p><h3 id=\"globalvars\"><code class=\"language-plaintext highlighter-rouge\">.globalVars</code></h3><p>This is a dictionary of all the global variables (variables that are NOT reset with <code class=\"language-plaintext highlighter-rouge\">.newContext()</code>).</p><h3 id=\"runfrom\"><code class=\"language-plaintext highlighter-rouge\">.runfrom</code></h3><p>The state that ran the <code class=\"language-plaintext highlighter-rouge\">@run</code> command for a new context, or <code class=\"language-plaintext highlighter-rouge\">start</code>. It is stored in <code class=\"language-plaintext highlighter-rouge\">@runfrom</code>.</p><h3 id=\"reference\"><code class=\"language-plaintext highlighter-rouge\">.reference</code></h3><p>The state that went to the current one with <code class=\"language-plaintext highlighter-rouge\">@goto</code>. It is stored in <code class=\"language-plaintext highlighter-rouge\">@reference</code>.</p><h3 id=\"sourcetext\"><code class=\"language-plaintext highlighter-rouge\">.source[\"text\"]</code></h3><p>The original text put into <code class=\"language-plaintext highlighter-rouge\">story()</code>.</p><h3 id=\"sourceglobalvars\"><code class=\"language-plaintext highlighter-rouge\">.source[\"globalVars\"]</code></h3><p>The original global variables.</p><h3 id=\"sourcelocalvars\"><code class=\"language-plaintext highlighter-rouge\">.source[\"localVars\"]</code></h3><p>The original local variables.</p><h3 id=\"newcontextrunfrom-state\"><code class=\"language-plaintext highlighter-rouge\">.newContext([runfrom, [state]])</code></h3><p>Creates a new context of the story and returns it, keeping global variables, but resetting local variables.</p><h3 id=\"texttext\"><code class=\"language-plaintext highlighter-rouge\">.text(text)</code></h3><p>Formats the given <code class=\"language-plaintext highlighter-rouge\">text</code>. Note that if it starts with a space, the rest is treated as raw text, and does not get formatted.</p><h3 id=\"runstatestate\"><code class=\"language-plaintext highlighter-rouge\">.runState(state)</code></h3><p>Runs the given <code class=\"language-plaintext highlighter-rouge\">state</code>.</p><h3 id=\"runcode\"><code class=\"language-plaintext highlighter-rouge\">.run(code)</code></h3><p>Runs the given code.</p><h3 id=\"varexistsvar-as-str\"><code class=\"language-plaintext highlighter-rouge\">.varExists(var as str)</code></h3><p>Returns <code class=\"language-plaintext highlighter-rouge\">True</code> or <code class=\"language-plaintext highlighter-rouge\">False</code> based of whether <code class=\"language-plaintext highlighter-rouge\">var</code> exists.</p><h3 id=\"varexistsvar-as-list-tuple-set\"><code class=\"language-plaintext highlighter-rouge\">.varExists(var as list, tuple, set)</code></h3><p>Return a dictionary containing whether each variable in <code class=\"language-plaintext highlighter-rouge\">var</code> exists.</p><h3 id=\"getvariablevar-as-str\"><code class=\"language-plaintext highlighter-rouge\">.getVariable(var as str)</code></h3><p>Returns the value of <code class=\"language-plaintext highlighter-rouge\">var</code>, or <code class=\"language-plaintext highlighter-rouge\">False</code>.</p><h3 id=\"getvariablevar-as-list-tuple-set\"><code class=\"language-plaintext highlighter-rouge\">.getVariable(var as list, tuple, set)</code></h3><p>Return a dictionary containing the value of each variable in <code class=\"language-plaintext highlighter-rouge\">var</code>, or <code class=\"language-plaintext highlighter-rouge\">False</code>.</p><h3 id=\"setvariablevar-as-str\"><code class=\"language-plaintext highlighter-rouge\">.setVariable(var as str)</code></h3><p>Resets the value of <code class=\"language-plaintext highlighter-rouge\">var</code>.</p><h3 id=\"setvariablevar-as-strval\"><code class=\"language-plaintext highlighter-rouge\">.setVariable(var as str,val)</code></h3><p>Sets the value of <code class=\"language-plaintext highlighter-rouge\">var</code> to the string value of <code class=\"language-plaintext highlighter-rouge\">val</code>.</p><h3 id=\"setvariablevar-as-list-tuple-set\"><code class=\"language-plaintext highlighter-rouge\">.setVariable(var as list, tuple, set)</code></h3><p>Resets the value of all variables in <code class=\"language-plaintext highlighter-rouge\">var</code>.</p><h3 id=\"setvariablevar-as-dict\"><code class=\"language-plaintext highlighter-rouge\">.setVariable(var as dict)</code></h3><p>Sets the value of each variable in <code class=\"language-plaintext highlighter-rouge\">var</code> to the value of it.</p><h3 id=\"simpleconditioncondition\"><code class=\"language-plaintext highlighter-rouge\">.simpleCondition(condition)</code></h3><p>Returns the value of a simple condition.</p><h3 id=\"testcondition\"><code class=\"language-plaintext highlighter-rouge\">.test(condition)</code></h3><p>Returns the value of a condition.</p><h2 id=\"story-static-methods\"><code class=\"language-plaintext highlighter-rouge\">story</code> Static Methods</h2><p>These are some methods you can call on the <code class=\"language-plaintext highlighter-rouge\">story</code> class itself.</p><h3 id=\"storyremoveindenttext\"><code class=\"language-plaintext highlighter-rouge\">story.removeIndent(text)</code></h3><p>This function removes as many spaces as possible from the left side of <code class=\"language-plaintext highlighter-rouge\">text</code>, in an equal amount of columns.</p><h3 id=\"storynumbertext\"><code class=\"language-plaintext highlighter-rouge\">story.number(text)</code></h3><p>This function tries to convert <code class=\"language-plaintext highlighter-rouge\">text</code> to a <code class=\"language-plaintext highlighter-rouge\">float</code>. If it fails, returns <code class=\"language-plaintext highlighter-rouge\">False</code>.</p><h3 id=\"storyaskquestionoption-0option-1\"><code class=\"language-plaintext highlighter-rouge\">story.ask(question,option 0,option 1,...)</code></h3><p>This function asks the user to select an option, and then return the key (0, 1, …) of the option selected.</p><h3 id=\"storyaskquestionlist-of-options\"><code class=\"language-plaintext highlighter-rouge\">story.ask(question,list of options)</code></h3><p>This function is like the first <code class=\"language-plaintext highlighter-rouge\">story.ask</code>, except is takes a list of options instead of spread out options.</p><h3 id=\"storyaskquestionanswer-as-str\"><code class=\"language-plaintext highlighter-rouge\">story.ask(question,answer as </code>str<code class=\"language-plaintext highlighter-rouge\">)</code></h3><p>This function asks the user to input an answer to <code class=\"language-plaintext highlighter-rouge\">question</code>, then returns whether their answer matched your <code class=\"language-plaintext highlighter-rouge\">answer</code>.</p><h3 id=\"storyaskquestion\"><code class=\"language-plaintext highlighter-rouge\">story.ask(question)</code></h3><p>This function returns <code class=\"language-plaintext highlighter-rouge\">True</code> or <code class=\"language-plaintext highlighter-rouge\">False</code> based on whether the user selects <code class=\"language-plaintext highlighter-rouge\">Yes</code> or <code class=\"language-plaintext highlighter-rouge\">No</code>.</p>",
"group": "For Developers",
"keyword": " story"
},
{
"url": "/posts/text",
"title": "Text",
"content": "<h1 id=\"text\">Text</h1><p>This article explains how to display (print) text to the user.</p><h2 id=\"waiting-for-enter\">Waiting for Enter</h2><p>To print text, just add it to your block:</p><pre><code class=\"language-storymatic\">start Welcome to my first story!</code></pre><p>Using this method will wait for the user to press Enter before executing the next command. For example, in</p><pre><code class=\"language-storymatic\">start Welcome to my first story! Do you like it?</code></pre><p>the user will have to press Enter after seeing <code class=\"language-plaintext highlighter-rouge\">Welcome to my first story!</code> to view the next line.</p><h2 id=\"nowait\">@nowait</h2><p>There is a simple way to print the text without waiting for Enter, which is by using the <code class=\"language-plaintext highlighter-rouge\">@nowait</code> command. Just type <code class=\"language-plaintext highlighter-rouge\">@nowait</code> before your text to make sure that it instantly prints.</p><h3 id=\"example\">Example</h3><pre><code class=\"language-storymatic\">start On this line, the user has to press Enter to go to the next line. @nowait This line will print and skip the Enter key.</code></pre><h2 id=\"wait\">@wait</h2><p>A good thing to use with <code class=\"language-plaintext highlighter-rouge\">@nowait</code> is <code class=\"language-plaintext highlighter-rouge\">@wait</code>, which waits for the specified amount of seconds. You write it like this: <code class=\"language-plaintext highlighter-rouge\">@wait {time}</code>.<code class=\"language-plaintext highlighter-rouge\">time</code> can be a whole number from 1 to 10, or a decimal number from <code class=\"language-plaintext highlighter-rouge\">0.1</code> to <code class=\"language-plaintext highlighter-rouge\">9.9</code> with one decimal digit.</p><h3 id=\"example-1\">Example</h3><pre><code class=\"language-storymatic\">start On this line, the user has to press Enter to go to the next line. @nowait This line will print and skip the Enter key. @wait 2 @nowait This line will print and skip the Enter key after 2 seconds. @wait 1 @nowait This line will print and skip the Enter key after 1 second. @wait 5.7 @nowait This line will print and skip the Enter key after 5.7 seconds.</code></pre>",
"group": "Basics",
"keyword": " text"
},
{
"url": "/posts/variables",
"title": "Variables",
"content": "<h1 id=\"variables\">Variables</h1><p>Variable are an amazing way to store data about the user! Learn how to work with them in this article!</p><h2 id=\"overview\">Overview</h2><p>A variable contains data. It can either be declared as a <a href=\"#global-vs-local\">global or local variable</a>, and can be declared as a local from within a block.</p><p>To set a local variable, use <code class=\"language-plaintext highlighter-rouge\">${varname} = {value}</code>.To set a global variable, use <code class=\"language-plaintext highlighter-rouge\">@global ${varname} = {value}</code>.</p><h2 id=\"example\">Example</h2><pre><code class=\"language-storymatic\">@global $money = 500$name = Stevestart $name has $money dollars.</code></pre><p>In the example above, we declared <code class=\"language-plaintext highlighter-rouge\">money</code> as a global variable with the value <code class=\"language-plaintext highlighter-rouge\">500</code>, and <code class=\"language-plaintext highlighter-rouge\">name</code> as a local variable with the value <code class=\"language-plaintext highlighter-rouge\">Steve</code>.To use variables, you just type <code class=\"language-plaintext highlighter-rouge\">${varname}</code> in your text. To make sure that the parser isn’t confused, you can also use <code class=\"language-plaintext highlighter-rouge\">{${varname}}</code>. Ex: <code class=\"language-plaintext highlighter-rouge\">{$name}</code>.</p><h2 id=\"redeclaring-variables\">Redeclaring Variables</h2><p>You can change variable by redeclaring them in a block:</p><pre><code class=\"language-storymatic\">@global $money = 500$name = Stevestart $name has $money dollars. $money = 1000 Now $name has $money dollars!</code></pre><p>Note that when redeclaring, you do not use <code class=\"language-plaintext highlighter-rouge\">@global</code>, even if the variable is global. You can also declare variable from within a block:</p><pre><code class=\"language-storymatic\">@global $money = 500$name = Stevestart $friend = Annie $name has $money dollars. $money = 1000 Now $name has $money dollars! $name's friend $friend also has $money dollars!</code></pre><p>When declaring a variable from within a block, you can also use the names of variables within the value:</p><pre><code class=\"language-storymatic\">@global $money = 500$name = Stevestart $friend = $name's friend Annie $name has $money dollars. $money = 1000 Now $name has $money dollars! $friend also has $money dollars!</code></pre><h2 id=\"changing-variables\">Changing Variables</h2><p>You can also add, subtract, multiply, or divide the current value of a variable to another value by using different operators.</p><ul> <li>For <code class=\"language-plaintext highlighter-rouge\">+</code>, use <code class=\"language-plaintext highlighter-rouge\">+=</code>: <code class=\"language-plaintext highlighter-rouge\">$money += 20</code>.</li> <li>For <code class=\"language-plaintext highlighter-rouge\">-</code>, use <code class=\"language-plaintext highlighter-rouge\">-=</code>: <code class=\"language-plaintext highlighter-rouge\">$money -= 20</code>.</li> <li>For <code class=\"language-plaintext highlighter-rouge\">*</code>, use <code class=\"language-plaintext highlighter-rouge\">*=</code>: <code class=\"language-plaintext highlighter-rouge\">$money *= 20</code>.</li> <li>For <code class=\"language-plaintext highlighter-rouge\">/</code>, use <code class=\"language-plaintext highlighter-rouge\">/=</code>: <code class=\"language-plaintext highlighter-rouge\">$money /= 20</code>.</li></ul><pre><code class=\"language-storymatic\">@global $money = 500$name = Stevestart $friend = $name's friend Annie $name has $money dollars. $money += 630 Now $name has $money dollars! $friend also has $money dollars!</code></pre><p>There’s also shortcuts for adding and subtracting one: <code class=\"language-plaintext highlighter-rouge\">${varname}++</code> and <code class=\"language-plaintext highlighter-rouge\">${varname}--</code>.</p><h3 id=\"appending-text\">Appending Text</h3><p>You can also append text to a variable with <code class=\"language-plaintext highlighter-rouge\">.=</code>. For example,</p><pre><code class=\"language-storymatic\">$text = astart $text $text .= b $text $text .= c $text</code></pre><h2 id=\"global-vs-local\">Global vs. Local</h2><p>Global variables are not reset when the program switches to a different context, while local variables are.</p><h2 id=\"special-variables\">Special Variables</h2><p>There are two special variables: <code class=\"language-plaintext highlighter-rouge\">@runfrom</code> and <code class=\"language-plaintext highlighter-rouge\">@reference</code>.</p><p>When you use <code class=\"language-plaintext highlighter-rouge\">@goto</code> or <code class=\"language-plaintext highlighter-rouge\">@run</code> to run a different block, <code class=\"language-plaintext highlighter-rouge\">@reference</code> is set to the state that ran <code class=\"language-plaintext highlighter-rouge\">@goto</code> or <code class=\"language-plaintext highlighter-rouge\">@run</code>.</p><p>When you use <code class=\"language-plaintext highlighter-rouge\">@context</code>, <code class=\"language-plaintext highlighter-rouge\">@runfrom</code> is set to the state that ran <code class=\"language-plaintext highlighter-rouge\">@context</code>.</p>",
"group": "Variables",
"keyword": " variables"
},
{
"url": "/posts/while-loop",
"title": "While Loops and Do-While Loops",
"content": "# While Loops and Do-While LoopsWhile loops execute a statement while a condition is `true`. This article explains how to make them.## OverviewA while loop executes some statements while a condition is `true`. If the condition was originally `false`, a while loop will not run.A do-while loop will always run at least once, even if the condition starts out as `false`.You can write a while loop by writing `@while {condition}`, and putting statements inside.You can write a do-while loop by writing `@dowhile {condition}`, and putting statements inside.## Example``` storymatic$money = 0start @while $money <= 500 $money += 50 @nowait $money```The example above will increment `money` by `50` until it is greater than `500`. However, if `money` is already greater than `500`, it will not run.The example below will do the same thing, but will always increment `money` at least once.``` storymatic$money = 0start @dowhile $money <= 500 $money += 50 @nowait $money```",
"group": "Loops",
"keyword": " while-loop"
}
]
Variable are an amazing way to store data about the user! Learn how to work with them in this article!
Overview
A variable contains data. It can either be declared as a global or local variable, and can be declared as a local from within a block.
To set a local variable, use ${varname} = {value}.
To set a global variable, use @global ${varname} = {value}.
Example
@global $money = 500
$name = Steve
start
$name has $money dollars.
In the example above, we declared money as a global variable with the value 500, and name as a local variable with the value Steve.
To use variables, you just type ${varname} in your text. To make sure that the parser isn’t confused, you can also use {${varname}}. Ex: {$name}.
Redeclaring Variables
You can change variable by redeclaring them in a block:
@global $money = 500
$name = Steve
start
$name has $money dollars.
$money = 1000
Now $name has $money dollars!
Note that when redeclaring, you do not use @global, even if the variable is global. You can also declare variable from within a block:
@global $money = 500
$name = Steve
start
$friend = Annie
$name has $money dollars.
$money = 1000
Now $name has $money dollars!
$name's friend $friend also has $money dollars!
When declaring a variable from within a block, you can also use the names of variables within the value:
@global $money = 500
$name = Steve
start
$friend = $name's friend Annie
$name has $money dollars.
$money = 1000
Now $name has $money dollars!
$friend also has $money dollars!
Changing Variables
You can also add, subtract, multiply, or divide the current value of a variable to another value by using different operators.
For +, use +=: $money += 20.
For -, use -=: $money -= 20.
For *, use *=: $money *= 20.
For /, use /=: $money /= 20.
@global $money = 500
$name = Steve
start
$friend = $name's friend Annie
$name has $money dollars.
$money += 630
Now $name has $money dollars!
$friend also has $money dollars!
There’s also shortcuts for adding and subtracting one: ${varname}++ and ${varname}--.
Appending Text
You can also append text to a variable with .=. For example,
$text = a
start
$text
$text .= b
$text
$text .= c
$text
Global vs. Local
Global variables are not reset when the program switches to a different context, while local variables are.
Special Variables
There are two special variables: @runfrom and @reference.
When you use @goto or @run to run a different block, @reference is set to the state that ran @goto or @run.
When you use @context, @runfrom is set to the state that ran @context.