Property Use in Conditionals
Properties can be opt-out from being accessible (or appearing) in conditional expressions. They will always be available by default but users can decide to hide them from conditional expressions so entity Scopes will ignore them while being constructed before a expression evaluation occurs.
Opting out while working with Rust
While working with Rust, to opt out a property from being accessible from
both buffs and modifiers condition expressions the hide_from_condition
method can be used. This method should be chained when the property is
being created.
#![allow(unused)] fn main() { let p = Property::new("some_property_name", Value::from("some value")) .hide_from_conditions(true) }
In case that we want to change the visibility of a property that already exists we can still do it ignoring the return value from the method itself.
#![allow(unused)] fn main() { // let's assume that p is an already defined and initialized property instance p.hide_from_conditions(true) }
We can also make a hidden property visible passing false as parameter to the
method instead.
Opting out while working with Lua
In similar way, to opt out a property appearance in condition expressions
users can chain the hide_from_conditions method in the newly created
property.
local p = alacrity.Property.new("some_property_name", "some value"):hide_from_conditions(true)
As in Lua we rarely create properties using this constructor but by using a
table as literal in methods that support property construction from tables
we can also opt out their condition expression appearance using an additional
field hide_from_conditions with a boolean value with our preference.
-- let's create an entity with some table literal properties
local e = alacrity.Entity.new({
name = "Some Entity",
description = "Some Entity Description",
attributes = {},
properties = {
{
name = "some_property_name",
value = "some value",
hide_from_conditions = true,
}
}
})
If this field is not present in the table, Alacrity will assume its value
is false.
ℹ️ Info
The field is called
hide_from_conditionsto maintain name consistency and make it is easier for users to remember as the field name matches the function one.
As with the Rust API, users can toggle the visibility of a property that
already exists at any time using the hide_from_conditions method in the
property instance itself.
-- let's assume that p is an already defined and initialized property
p:hide_from_conditions(true)