Skip to main content

Changing keysSevenKewpSven Co-op

Two entities let you change almost any key of another entity while the map runs: trigger_changevalue writes a value into a key, and trigger_copyvalue copies one entity's key into another's. Both can also combine the old value with the new one, so they can add, multiply, append text and more. See the Changing values guide for small setups that use them.

trigger_changevalue​

When you trigger a trigger_changevalue, it writes New value into the key Key name of its destination entities.

KeyWhat it holds
Destination entity (target)Every entity with this name, or !activator or !caller
Key name (m_iszValueName)The key to change, for example health, rendercolor, scale or message, or a custom key
New value (m_iszNewValue)A number, three numbers x y z, or text
Type of value (m_iszValueType)The operation (see Operations). The default is Replace (0)
Treat new value as (value_type)Literal value (0), the default, uses New value as you wrote it. Locus Ratio (1), Locus Position (2) and Locus Velocity (3) treat it as a locus key, which the entity works out for the activator each time it fires
Trigger after operation (message)The entity that gets a Toggle after the change, which can be a name, !activator or !caller

New value can also be a named constant, such as FL_ONGROUND, SOLID_NOT, EF_NODRAW, MOVETYPE_FLY, kRenderTransAdd or CLASS_PLAYER, in capital or small letters. If you put a ~ in front of a number or a constant, the entity flips every bit of it, so together with the operation AND it clears those bits.

trigger_copyvalue​

When you trigger a trigger_copyvalue, it reads Source key of the source entity and writes it into Destination key of the destination entity, with the same operations. With the flag Constant, it copies again at an interval, so one key follows another.

KeyWhat it holds
Source entity (netname)The first entity with this name, or !activator or !caller
Source key (m_iszSrcValueName)The key to read
Destination entity (target)The first entity with this name, or every entity with it if you set Multiple destinations, or !activator or !caller
Destination key (m_iszDstValueName)The key to write
Float conversion (m_iFloatConversion)How a number with decimals becomes text or a whole number. The choices with 6, 5, 4, 3, 2 or 1 decimal places set the text, and they round a whole number down. The other choices round to the nearest whole number, round up or round down
Copy interval (dmg)How many seconds pass between two copies in constant mode, where 0 copies every frame

Its flags are:

  • Constant (8) - Each trigger copies once. After an On, or a Toggle that turns it on, it also copies again every Copy interval seconds, until it gets an Off, or a Toggle that turns it off
  • Start on (16) - Together with Constant, constant mode runs from the start of the map
  • Multiple destinations (128) - Every entity with the destination name gets the value, and not only the first

Operations​

The operation decides how the key's old value and the new or copied value combine, and the destination key's type decides the math:

  • whole numbers stay whole, and numbers with decimals keep their decimals
  • a vector key is worked out one part at a time, so three numbers such as 64 0 0 go into it part by part, and a single number goes into every part
  • text keys only accept Replace and Append
ValueOperationValueOperation
0Replace11Append, for text
1Add2Multiply
3Subtract4Divide
16Power12Modulo, on whole numbers
5AND6OR
13XOR15Clear bits
7, 8, 14NAND, NOR, NXOR30, 31Min, Max
9Direction to angles10Angles to direction
17, 18, 19, 23Sine, cosine, tangent and cotangent of the new value20, 21, 22, 24Arcsine, arccosine, arctangent and arccotangent of the new value

Direction to angles and Angles to direction turn the key's old value into the other form and ignore the new value. Trigonometric funcs. behavior (m_trigonometricBehaviour) sets the unit of the angle functions, Degrees (0), the default, or Radians (1), and with Degrees, the sine of 30 is 0.5. Append spaces (m_iAppendSpaces) is the number of spaces the entity adds after a text result. If an operation divides by zero, the key keeps its old value.

Both entities share these flags, which change the values before the operation:

  • Don't use X (1), Don't use Y (2) and Don't use Z (4) - That part of a vector stays as it is
  • Invert target value (32) - The old value becomes negative before the operation
  • Invert source value (64) - The new value becomes negative before the operation

What can change​

A key the entity reads each time it uses it takes effect at once. These keys are health, max_health, dmg, speed, wait, delay, target, message, frags, the render keys, spawnflags, solid, movetype, effects, gravity, origin, angles, velocity, the unkillable key of a monster, in both directions, and custom keys.

Some keys do more than store a value:

Some entities copy a key when they spawn, or only pass it on to the players' games when you trigger them. These entities apply a change to the keys below themselves, with the same defaults and limits as when the map loads:

EntityKeysWhat a change does
env_fog, env_fogzoneEvery key and flag, and the position of an env_fogzoneEvery player sees the new fog at once
ambient_genericVolume, Pitch, WAV NameA looping sound that plays changes its volume or pitch at once, and a new sound stops the old one and plays at once
func_rotatingRotation SpeedIt spins at the new speed at once, and 0 stops it
func_conveyorConveyor SpeedThe texture scrolls at the new speed too
trigger_pushIts angles (Pitch Yaw Roll), Speed of pushIt pushes in the new direction and at the new speed, and a speed of 0 is 100, as at spawn
MonstersHealth, Max healthA health above the monster's maximum raises the maximum, and a maximum below its health lowers the health
monstermakerNumber of MonstersA maker that made its last monster starts again
light, light_spotCustom AppearanceA light that is on shows the new pattern at once
env_explosionMagnitudeThe fireball of the next explosion has the new size
env_overlayEvery key but the picture and the channelThe players who see it get the new values at once
color_correction, color_correction_volumeEvery key but the fileEvery player gets the new values at once, and a fade goes on from where it is
env_dlight, env_elightRadius, Light colorA light that is on changes at once
env_skyParallax scale, Sky fog color, Sky fog density, Skybox fog, its positionThe 3D sky changes at once while it is the sky
multi_managerA target's delayThe target fires at the new time, still once
func_tankRate of Fire, Bullet accuracyA rate of 0 is one shot a second and an accuracy outside the list is Perfect, as at spawn

If an entity only reads a key when it spawns, a change sets the stored value but doesn't change what the entity does, for example a door's lip. The speed of a func_tracktrain is one of these keys, so use a train_setspeed to change a train's speed. If the entity can't tell what a key holds, only Replace works on it, and any other operation leaves the key as it is. With developer 1 set in the console, the console then shows trigger_changevalue "<name>": key "<key>" of <class> "<name>" can't be read, so only Replace works on it (nothing changed), with trigger_copyvalue at the start for that entity.

Both entities refuse the keys model, viewmodel, weaponmodel, noise, noise1, noise2 and noise3, because the game would have to precache (load) a new file. With developer 1 set in the console, the console then shows Key "<key>" of <class> "<name>" can't be changed at run time (it would need a precache). The noise keys of calc_ratio, the calc velocity entities and env_state hold numbers and target names, not sounds, so you can change them.

Both entities also refuse the key classname, because the entity would keep the behavior of its own class under the name of another class. With developer 1 set in the console, the console then shows <class>: classname "<value>" ignored (an entity's class can't be changed).

A few more keys are refused because changing them would break the entity:

  • The sound of an ambient_generic, unless the map has already loaded that sound, for example because another entity uses it, because a new sound would have to be precached. An MP3 can't be changed either
  • Appearance (the style number) of a light or light_spot, because the light would then switch the lights of another style number
  • Channel of an env_overlay, because the players' screens keep it on its channel

Some entities keep a model or a sprite in a key of their own and refuse a change to that key after they spawn, with the same kind of console line, and keep working with the old value. These keys are:

The Monster Type (monstertype) of a monstermaker and a new item key of a game_player_equip only accept a class the map already loads: a class the map places or a maker makes, a morph monster, or a weapon. The entities refuse any other class with the same console line, and a maker with # keys keeps its class.

Changes since 1.38​

  • trigger_changevalue and trigger_copyvalue are new

See also​