Skip to content

Arcscript

Arcweave has its own scripting language, arcscript, with basic scripting capabilities. You can use arcscript in the following two ways:

Arcscript in branches

Arcscript is used in branches to control flow with if, elseif, and else conditions.

Part of an Arcweave flowchart showing a branch that includes , , and  conditions and the elements they lead to.

This page does not cover arcscript in branches; see branches.

Arcscript segments

An Arcweave element the content of which includes rich text and arcscript code.

Arcscript segments are single lines of dialogue that you can add in element content and connection labels. They support assignment and conditional statements.

Add arcscript

To insert an arcscript segment into the content of an element or connection label:

  1. Double-click the element or label to enter content editing mode.
  2. Place the cursor on the line where you want to insert the arcscript segment.
  3. Click the Arcscript segment icon in the formatting toolbar.
  4. Press Enter to exit the arcscript segment and continue writing in the next line.

✅ You can also toggle an arcscript segment using the shortcut Ctrl/Cmd + Shift + C.

Auto-complete

While you type in an arcscript segment or branch, Arcweave will provide auto-complete suggestions.

Animated GIF demonstrating the auto-complete feature in arcscript.

Suggestions include:

  • Variable names
  • Functions
  • Operators
  • Literals

Use the arrow keys to select the relevant suggestion and press Enter to auto-complete it in your code.

Assignment statements

Assignment statements are of the form of variable = expression. For example:

arcscript
x = 5
x = y + 5
name = "Tim"
has_key = true

ℹ️ To use a variable in an arcscript segment or branch, you must first declare it in Global variables (bottom left of your window).

Arcscript also supports the following operations, with their respective operators:

OperationOperatorDescription
Addition+=Adds the right-hand value to the variable and assigns the result.
Subtraction-=Subtracts the right-hand value from the variable and assigns the result.
Multiplication*=Multiplies the variable by the right-hand value and assigns the result.
Division/=Divides the variable by the right-hand value and assigns the result.
Modulo%=Applies modulo to the variable using the right-hand value and assigns the result.

For example:

arcscript
x = 5
x += 10
x -= 2

Conditional Statements

Conditional statements are of the form: if.../elseif.../else/endif. Inside conditional statements, you may have:

  • other statements (assignments or conditionals).
  • text content.

Example of a conditional statement containing an assignment:

arcscript
if x == 5
  y = 4
endif

Example of a conditional statement containing some text content:

arcscript
if wielding_shield
  The knight is wielding a large shield.
endif

Example of a conditional statement containing some text content and a variable assignment:

arcscript
if hasKey
  You unlock the door!
  doorUnlocked = true
else
  You cannot open the door
endif

Example of using elseif for multiple outcomes:

arcscript
if age >= 18
  Look at you! All grown up!
  type = "adult"
elseif age > 0
  You are not an adult yet.
  type = "child"
else
  Are you sure you have been born?
  type = "unborn"
endif

Expressions

Arcsript supports expressions that use the following arithmetic operators:

OperatorNameDescription
+AdditionAdds two numeric values together.
-SubtractionSubtracts the right-hand value from the left-hand value.
*MultiplicationMultiplies two numeric values.
/DivisionDivides the left-hand value by the right-hand value.
%ModuloReturns the remainder of a division between two numeric values.
( )ParenthesesGroups parts of an expression to control evaluation order.

Expressions may combine literals, function calls and variables.

Conditions

Conditional operators

OperatorNameDescription
==, isEqualityChecks whether two values are equal.
!=, is notInequalityChecks whether two values are not equal.
>Greater thanChecks whether the left-hand value is greater than the right-hand value.
>=Greater than or equalChecks whether the left-hand value is greater than or equal to the right-hand value.
<Less thanChecks whether the left-hand value is less than the right-hand value.
<=Less than or equalChecks whether the left-hand value is less than or equal to the right-hand value.

Logical operators

OperatorNameDescription
&&, andLogical ANDEvaluates to true if both conditions are true.
||, orLogical OREvaluates to true if at least one condition is true.
!, notLogical NOTNegates a condition, turning true into false and vice versa.

Built-in functions

The functions that are currently supported in Arcscript:

FunctionReturns
abs(n)The absolute value of a number
sqr(n)The square of a number
sqrt(n)The square root of a number
min(n1, n2, ...)The minimum of a series of numbers
max(n1, n2, ...)The maximum of a series of numbers
random()A random decimal between (and including) 0 and (excluding) 1, i.e. in [0, 1)
reset(v1, v2, ...)Has no return value; resets the given variables to their initial value
resetAll(v1, v2, ...)Has no return value; resets all variables, except the given ones, to their initial value
resetVisits()Has no return value; resets all elements' visits to 0
roll(m, n)A roll of an n number of m-sided dice (e.g. for 2d6: n == 2, m == 6)
round(n)The number rounded to the nearest integer
show(e1, e2, ...)The evaluation and concatenation of its argument expressions
visits(el)The number of visits in a certain element

roll

A part of an Arcweave flowchart demonstrating a simple use of the roll function: roll returns a value that gets stored in a variable. Then, a branch compares the variable with a number and diverts the flow accordingly.

The roll(m, n) function simulates polyhedral die rolls from the classic tabletop RPGs.

Roll takes 2 integer numbers as its arguments:

  • m: the number of sides of the rolled die.
  • n: the number of dice rolled.

The function returns a random integer between (and including both) n and n*m, i.e. [n, n*m].

✅ If n = 1, you can omit the second argument and simply type roll(m).

For example, rolling for a number from 1 to 12:

arcscript
damage = roll(12)

Example of rolling 3d6 (3 six-sided dice) for a character's ability scores in Dungeons & Dragons:

arcscript
dexterity = roll(6, 3)

Example of a dynamic use, where the player suffers damage from 1 to max_damage:

arcscript
player_hp = player_hp - roll(max_damage)

But the roll(m, n) function can also be used in a conditional statement:

arcscript
if roll(max_damage) > player_hp
  Oops... This isn't good...
endif

show

The show(e1, e2, ...) function renders its arguments and concatenates them as one string.

For example, the following:

arcscript
show("Your score is ", score, "/", max_score, ".")

... for score == 3 and max_score == 256 returns:

  > Your score is 3/256.

You can use the show(e1, e2, ...) function in combination with text content, in elements. For example:

arcscript
if roll(max_damage) > player_hp
  Oops... This isn't good...
  You have died. In this game you scored
  show(score, " out of ", max_score, ".")
endif

visits

Call visits() with an element argument

The visits(element) function returns the number of times a specific element has been visited during the current playthrough.

The element argument must be a mention to an element. To mention an element inside visits():

  1. Place your cursor within the parentheses of visits().
  2. Type @ and begin entering the element's title.
  3. Select the correct element from the autocomplete list.

✅ Mentioning an element in arcscript works similarly to mentioning a component or board in rich text fields.

Call visits() without an argument

If visits() is called without an argument, it implicitly refers to the most recently loaded element in the flow. This means one of the two following cases:

  • When used inside an element's content, it refers to that element itself.
  • When used inside a connection label, it refers to the element that was visited immediately before.

✅ To reset the visits of all elements of your project, use the resetVisits() function. It is always called without arguments.

Examples

arcscript
The knight is guarding a mysterious gate. You see a name written above his head:
| "Conrad IV, Count of Exeter"
if visits(examine_the_painting) > 1
  You make a mental note of the knight's name.
endif

And if we are already in the Examine the painting element, we can write:

arcscript
The knight is guarding a mysterious gate. You see a name written above his head:
| "Conrad IV, Count of Exeter"
if visits() > 1
  You make a mental note of the knight's name.
endif

Errors

When a script has a compile-time error, this is denoted by an exclamation mark symbol, at the lower right corner of the container element.

✅ Hover your mouse cursor over the symbol to get more info on what the error is about.