Changing values: trigger_changevalue, trigger_copyvalue and trigger_condition
Three entities let you read and change other entities' settings while the map runs, so you can count, keep score, change a monster or a sign, and react when a value passes a limit. Without them, most entities keep the settings you gave them in the editor for the whole map:
trigger_changevaluewrites a new value into a key of another entitytrigger_copyvaluecopies a key from one entity to anothertrigger_conditionchecks a key and fires a target when the check is true or false
The first two sections cover what you must know, followed by four small setups you can build. See Changing keys for the full rules.
You work with key names
These entities don't use the names the editor shows, but the key names behind them, so you write health and not
Health, and message and not Entity Message. To see an entity's key names in J.A.C.K., turn off SmartEdit in
its properties, and the list then shows each key as the map stores it.
You can also make up keys of your own, called custom keys, which
work like variables. A custom key's name starts with $i_ for a whole number, $f_ for a number with
decimals, $v_ for three numbers and $s_ for text, such as $i_presses. You can give a custom key to any entity,
and an info_target is a good place to keep them, because it does nothing
else. Give each custom key a start value in the editor, with SmartEdit off, so the first change has a value to work
on.
Not every key changes what you see
A key the entity reads each time it uses it changes the entity at once, which is true for health, rendercolor,
renderamt, target, message, speed and many more. For example, if you change a door's target, the door fires
the new target the next time it opens. If an entity only reads a key when it spawns, such as a door's lip, a change
sets the stored value but doesn't change what the entity does.
The entities refuse the model key and the sound keys, because the game can't load a new file while the map runs,
and they also refuse classname. See What can change for the
full list.
Setup 1: a sign that counts button presses
A sign above a button shows how often players have pressed it, for example "Presses: 3".
- Make an
info_targetnamedcounter - Turn SmartEdit off and give
counterthe custom key$i_presseswith the value0 - Make a
point_worldtextnamedsign, with Entity Message set toPresses: 0 - Make a
func_buttonwith Target set toadd - Make a
trigger_changevaluenamedadd, with Destination entity set tocounter, Key name set to$i_pressesand New value set to1 - Set Type of value to "Add" and Trigger after operation to
labelonadd - Make a
trigger_changevaluenamedlabel, with Destination entity set tosign, Key name set tomessageand New value set toPresses: - Set Type of value to "Replace", Append spaces to
1and Trigger after operation toshowonlabel - Make a
trigger_copyvaluenamedshow, with Source entity set tocounterand Source key set to$i_presses - Set Destination entity to
sign, Destination key tomessageand Type of value to "Append" onshow
func_buttontrigger_changevalueaddtrigger_changevaluelabeltrigger_copyvalueshowEach press adds 1 to $i_presses, then label writes "Presses: " back onto the sign (with the space from Append
spaces), and show adds the count to the end of the text. Every player sees the new text at once.
A sign that counts each press of a button
Setup 2: a boss that can't die until the generator is destroyed
A Cyber Minotaur takes damage as usual, but it can't die while its power generator stands.
- Make a
monster_cyberminotornamedboss, with Unkillable set to "Yes" - Make a
func_breakablefor the generator, with Target set toweaken - Make a
trigger_changevaluenamedweaken, with Destination entity set toboss, Key name set tounkillable, New value set to0and Type of value set to "Replace"
While Unkillable is on, damage never takes the boss below 1 health. When the generator breaks, it fires weaken,
which turns the key off, so the next hit can kill the boss.
Setup 3: a door that opens when the boss is badly hurt
When the boss from Setup 2 has less than 500 health left, a door to the escape route opens.
- Make a
trigger_condition, with Monitored entity set toboss, Monitored key set tohealthand Compare-value set to500 - Set Comparator to "< (Less)" and Target for 'true'-case to the name of the door
- Set In constant mode fire when to "Result has changed"
- Make a
func_doorfor the escape route, with the flag Toggle, so it stays open
A trigger_condition is on from the start of the map, unless you set Start Off. It checks the key every Check
interval seconds, which is 0.1 by default. With "Result has changed", it only fires when the result changes from
false to true or back, so the door opens once, at the moment the boss's health drops below 500.
Setup 4: a light that follows a train
A glowing sprite moves with a func_train, but it isn't part of the train.
- Make a
func_trainnamedcart, with an origin brush in its middle, which is the point the train moves along its path and the point the sprite goes to - Make an
env_spritenamedlamp - Make a
trigger_copyvalue, with Source entity set tocart, Source key set toorigin, Destination entity set tolampand Destination key set toorigin - Set Copy interval to
0and the flags Constant and Start on on thetrigger_copyvalue
With Constant and Start on, the trigger_copyvalue copies the train's position to the sprite from the start
of the map, and with a Copy interval of 0, it copies every frame.
Things to watch for
- If the monitored entity or the monitored key of a
trigger_conditionis empty, it removes itself at its first check, and withdeveloper 1set in the console, the console shows a message - A
trigger_conditionpasses itself on as the activator, unless you set its flag Keep activator - In constant mode with "Result has changed", the first check counts the last result as true, so a first result that is true fires nothing, and a first result that is false fires the false target at once. Set Ignore initial result if you don't want the first check to fire
- A division by zero leaves the key as it was, and with
developer 1set in the console, the console shows a message - A
trigger_copyvaluewithout Multiple destinations only writes to the first entity with the destination name
Further reading
- Changing keys - every key, operation and flag of these entities
- Entity keyvalues - key names and custom keys
- Locus guide - asking another entity for a value at the moment you need it