Chord / Vocabulary & Text / define trait
define trait
A trait is a reusable bundle of data, states, scores, phrases, and
behavior that entities compose with.
define trait <name> … end trait declares one. The block below carries one of everything:
define trait feedable
data
food: entity
ration: optional number
diet: one of hay, seed, fish
states, reversible: hungry, content
score fed worth 10
phrases en-US
no-food:
You have nothing {the item} would want.
already-fed:
{capitalize the item} has had quite enough already.
fed:
The feed vanishes in seconds.
on feeding it
the player must have its food: no-food
it must be hungry: already-fed
change it to content
award fed
phrase fed
end on
end trait
The parts, top to bottom:
datadeclares fields. Each is<name>: <type>, where the type isentity,number,name, orone of <word>, <word>, …for a fixed set.optionalbefore the type makes the field omittable;, starts <value>(not shown here) gives a default. Fields are read and written withits <field>/set its <field> to ….statesandscoreare the same owner lines as everywhere else, here owned by the trait: every entity composed withfeedablegets thehungry/contentstates and can awardfed.phrasesis a locale block scoped to the trait.on/afterclauses are the trait's behavior, withitmeaning the composed entity.
An entity picks the trait up on a composition line, passing its data
with with:
create the pygmy goats
aka goats
feedable with food the handful of feed and diet hay
in the Petting Zoo
A state name declared by two different composed traits on one entity is
a collision (analysis.state-collision), caught at load time.