Closed Noah2610 closed 3 years ago
Working entity config variables on master
.
Example config:
(
components: [
// This component has to be given before variables can be used.
VariableRegister({
// Can optionally set default variables here.
// If not set, all variables will default to `Null`,
// when used the first time.
"my_variable": Null,
"my_number": 4.20,
"some_boolean": false,
}),
],
events: {
// `If`, `Echo`, and some other actions now take a new `Expression` value.
// I still need to document this properly.
//
// The `Var(variable_name)` expression returns the given variable value.
// This can be used here to pass the expression value of the variable to
// the `Echo` action to print that value to the terminal.
Init: Echo(Var("my_number")),
Interval(1000): Group([
Echo(Var("some_boolean")),
// This new `VariableAction` action currently only has the `Set` action.
// It takes two arguments, the variable name as a string and the value
// to set the variable to as an expression.
VariableAction(Set(
"some_boolean",
// Expressions are powerful.
// They can be literal values (strings, numbers, booleans, and null),
// they can be operations (`Not`, `And`, `Or`, or mathematical operations like `Add`, `Sub`, etc.),
// or they can evaluate to a value from an entity's component or variable (`Var`, `Health`, `Velocity(Axis)`, etc.).
Not(Var("some_boolean")),
)),
]),
},
)
See documentation comments and available syntax for expressions: https://github.com/Noah2610/deathfloor/blob/c266806818403a942498514c03546a663e9867f9/src/expression/mod.rs#L1 https://github.com/Noah2610/deathfloor/blob/c266806818403a942498514c03546a663e9867f9/src/expression/value.rs#L4 https://github.com/Noah2610/deathfloor/blob/c266806818403a942498514c03546a663e9867f9/src/expression/operation.rs#L5 https://github.com/Noah2610/deathfloor/blob/c266806818403a942498514c03546a663e9867f9/src/expression/component_value.rs#L8
Add gettable and settable variables / state to entity config.
Example config: