Difference between revisions of "Expression"
m (Reverted edits by 172.31.67.197 (talk) to last revision by Ben) Tag: Rollback |
(Add screenshot of expression beaker button) |
||
Line 6: | Line 6: | ||
== Using Expressions == | == Using Expressions == | ||
[[File:Expression-beaker-button.jpg|alt=A screenshot of a Rule response where the "beaker" button for editing the expression is circled with red highlighter|thumb|Press the beaker button (circled here in red) to use an expression.]] | |||
Expressions are an important component of [[Rule|Rules]] in Castle. Typically, when editing a rule, any numeric value can be an expression. To edit an expression, look for the round beaker icon to the left of a number input. Press it to open a sheet to edit that expression. | Expressions are an important component of [[Rule|Rules]] in Castle. Typically, when editing a rule, any numeric value can be an expression. To edit an expression, look for the round beaker icon to the left of a number input. Press it to open a sheet to edit that expression. | ||
Revision as of 17:03, 17 May 2022
An Expression is a representation of a value that is resolved while the deck is playing. Some common uses for expressions include: Reading the value of variables, performing simple math, or creating randomness. Expressions can also be nested and combined to support more complex things, such as calculating health for characters, crafting procedural games and animations, and even making generative artwork.
Expressions always resolve to a numeric value.
Some expressions take arguments. For example, when reading the value of a Variable, you need to specify which variable to read. When adding two numbers, you need to specify which two numbers (or expressions) to add. Other expressions don't take any arguments, such as the Time elapsed since the card started.
Using Expressions
Expressions are an important component of Rules in Castle. Typically, when editing a rule, any numeric value can be an expression. To edit an expression, look for the round beaker icon to the left of a number input. Press it to open a sheet to edit that expression.
List of Expression Types
Some expressions are contextual to the enclosing Response. For example, the "Number of repeats finished" expression only appears if already inside a Repeat response.
Values
- A constant number. This is the same as not using an expression.
- The value of a variable
- The value of a Behavior property
Choices
- Weighted choose
- Choose
- Maximum
- Minimum
Randomness
- A random number with a Gaussian distribution
- Perlin noise in 2 dimensions
- A random number in a range
Spatial relationships
- The speed of an actor
- The angle of motion of an actor
- The angle from one actor to another (degrees)
- The distance between two actors
Arithmetic
- The number of Repeats finished
- Logarithm
- Power
- Modulo
- Divide
- Multiply
- Subtract
- Add
Clock
- Time elapsed since the card started
- The clock tempo
- Time since the last beat
- The current bar
- The current beat in the current bar
- Beats elapsed since the card started
Music
- The note played (only appears under the "track plays note" trigger)
Functions
- The number of actors with a Tag
- Degrees to radians
- Sine
- Clamp a value between two bounds
- Mix two values
- Round
- Round down
- Absolute value