Difference between revisions of "Expression"

From Castle Wiki
(Add links to all expression pages)
(Add tilt expressions)
 
(15 intermediate revisions by 4 users not shown)
Line 1: Line 1:
Expressions in Castle are used for many things, including calculating health for characters, crafting procedural games and animations, and even making generative artwork. Expressions sometimes take in some values as arguments and always return a result value.
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 ==
[[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.


== List of Expression Types ==
== List of Expression Types ==
The following is a list of expression types in the order that they are listed when viewed in the Castle "Choose expression type" sheet
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 ===
=== Values ===


* [[The value of a variable expression|The value of a variable]]
* A constant number. This is the same as not using an expression.
*[[A constant number expression|A constant number]]
*The value of a [[variable]]
*The value of a [[Behavior]] property


=== Choices===
=== Choices===


* [[Weighted choose expression|Weighted choose]]
* Weighted choose
*[[Choose expression|Choose]]
*Choose
*[[Maximum expression|Maximum]]
*Maximum
*[[Minimum expression|Minimum]]
*Minimum


===Randomness===
===Randomness===
Line 20: Line 29:
*[[A random number with a Gaussian distribution expression|A random number with a Gaussian distribution]]
*[[A random number with a Gaussian distribution expression|A random number with a Gaussian distribution]]
*[[Perlin noise in 2 dimensions expression|Perlin noise in 2 dimensions]]
*[[Perlin noise in 2 dimensions expression|Perlin noise in 2 dimensions]]
*[[A random number in a range expression|A random number in a range]]
*A random number in a range
 
===Spatial relationships===


===Spacial relationships===  
*The Y coordinate of the user's touch
*The X coordinate of the user's touch
*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 speed of an actor expression|The speed of an actor]]
*The number of [[Repeat|Repeats]] finished
*[[The angle of motion of an actor expression|The angle of motion of an actor]]
*Logarithm
*
*Power
[[The angle from one actor to another (degrees) expression|The angle from one actor to another (degrees)]]
* Modulo
*[[The distance between two actors expression|The distance between two actors]]
*Divide
* Multiply
* Subtract
* Add


=== Arithmetic ===
===[[Clock]]===


*[[The number of repeats finished expression|The number of repeats finished]]
*Time elapsed since the card started
*[[Logarithm expression|Logarithm]]
* The clock tempo
*[[Power expression|Power]]
*Time since the last beat
* [[Modulo expression|Modulo]]
* The current bar
*[[Divide expression|Divide]]
*The current beat in the current bar
* [[Multiply expression|Multiply]]
*Beats elapsed since the card started
* [[Subtract expression|Subtract]]
* [[Add expression|Add]]


===Clock===
=== [[Music]] ===


*[[Time elapsed since the card started expression|Time elapsed since the card started]]
* The note played (only appears under the "track plays note" trigger)
* [[The clock tempo expression|The clock tempo]]
*[[Time since the last beat expression|Time since the last beat]]
* [[The current bar expression|The current bar]]
*[[The current beat in the current bar expression|The current beat in the current bar]]
*[[Beats elapsed since the card started expression|Beats elapsed since the card started]]


=== Functions===
=== Functions===


*[[The number of actors with a tag expression|The number of actors with a tag]]
*The number of actors with a [[Tag]]
*[[Degrees to radians expression|Degrees to radians]]
*[[Smooth expression|Smooth]]
*[[Sine expression|Sine]]
*Degrees to radians
*[[Clamp a value between two bounds expression|Clamp a value between two bounds]]
*Sine
*[[Mix two values expression|Mix two values]]
*Clamp a value between two bounds
*[[Round expression|Round]]
*Mix two values
* [[Round down expression|Round down]]
*Round
*[[Absolute value expression|Absolute value]]
* Round down
*Absolute value
 
=== Sensors ===
 
* Device [[Tilt]] X
* Device Tilt Y

Latest revision as of 18:46, 27 January 2023

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

A screenshot of a Rule response where the "beaker" button for editing the expression is circled with red highlighter
Press the beaker button (circled here in red) to use an expression.

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

Spatial relationships

  • The Y coordinate of the user's touch
  • The X coordinate of the user's touch
  • 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
  • Smooth
  • Degrees to radians
  • Sine
  • Clamp a value between two bounds
  • Mix two values
  • Round
  • Round down
  • Absolute value

Sensors

  • Device Tilt X
  • Device Tilt Y