Difference between revisions of "Trigger changevalue"

From Sven Co-op
Jump to navigation Jump to search
 
(4 intermediate revisions by 2 users not shown)
Line 3: Line 3:
 
}}
 
}}
  
Trigger_changevalue can perform arithmetic and logic operations on base-keyvalues of entities, as well as replace their private keyvalues. See trigger_copyvalue for a variant of this with more options. Supports custom keyvalues.
+
Trigger_changevalue can perform arithmetic and logic operations on base-keyvalues of entities, as well as replace their private keyvalues. See [[trigger_copyvalue]] for a variant of this with more options. Supports custom keyvalues.
  
 
== Keyvalues ==
 
== Keyvalues ==
Line 10: Line 10:
 
{{Entity_keyvalue|Destination Keyvalue|m_iszValueName|Name of the key which's value is to be changed.}}
 
{{Entity_keyvalue|Destination Keyvalue|m_iszValueName|Name of the key which's value is to be changed.}}
 
{{Entity_keyvalue|Static source-value|m_iszNewValue|Value to be applied to the destination keyvalue.}}
 
{{Entity_keyvalue|Static source-value|m_iszNewValue|Value to be applied to the destination keyvalue.}}
{{Entity_keyvalue|Operation|m_iszValueType|This specifies how destination keyvalue and static source-value correlate. What exactly happens also depends on the types of the two. Check the notes section to get a detail explanation for usage of each choice.}}
+
{{Entity_keyvalue|Operation|m_iszValueType|This specifies how destination keyvalue and static source-value correlate. What exactly happens also depends on the types  
{{Entity_keyvalue|Append spaces (for strings)|m_iAppendSpaces|When the destination keyvalue is a string, this specifies how many spaces to append after the operations. You'll usually want  
+
of the two. There are some academic things in here, so I shall explain some of them:Pow: Source value to the power of destination value. To keep things simple, zero to the power of zero magically equals one and taking a negative value to the power of a non-integer will cause the base to be treated as positive.Mod: Short for "Modulo", this calculates the rest of a division. For example, 63 % 13 equals 11, because 63 - 13 = 50, 50 - 13 = 37, 37 - 13 = 24 and 24 - 13 = 11. Substracting a fifth time would deliver a negative result and is henceforth omitted. The actual computation of this value uses a smarter, fast method; this is just for presentiveness. Usage example: You have a value in seconds, e.g. 285, and want to know how many minutes and seconds that are, so you divide by 60 and get 4.75. Omitting the 0.75 you're left with 4. For the remaining seconds, you'd calculate 285 % 60 = 45, which
to use this with either the "Replace"- or "Append"-operation. This was implemented because Valve Hammer Editor omits any trailing spaces in keyvalues (but not leading ones).}}
+
is the same as 60 * 0.75. Then you'd know that 285 seconds equals 4 minutes plus 45 seconds. Real numbers and negative values are supported.AND, OR, XOR, NAND, NOR, NXOR: These are logic operands which operate bitwise; the leading 'N' indicates bitwise negation after the operation. Example: An entity's spawnflags are stored in an integer which consists of 32 bits. Say you want to set the 7th checkbox of an entity's spawnflags, you need to make sure the 7th bit is set to 1. You hence need the integer number where only the 7th bit is set, which is 2 ^ (7 - 1) = 2 ^ 6 = 64. However, you cannot simply add this
 +
to the existing spawnflags, because if the 7th bit was already set to 1, you'd cause it to be set to 0 and generate a carry which is sent to the 8th bit; the magic of positional notation systems - just as 500 + 500 equals 1000 in decimal, 100 + 100 equals 1000 in binary. You'd need to perform a bitwise OR. If you'd want only the 7th checkbox to be checked, you'd use replace-operation as usual. XOR means "Exclusive OR", as in "Either that or the other, but not both". AND means that both bits need to be 1 for the resulting bit to remain 1. You can imagine the logic operators perform 32 simultaneous operations on the combined 64 bits of two integers. Append (String concatenation): Appends your source value to the destination keyvalue. The later must be a string; otherwise this cannot work.}}
 +
{{Entity_keyvalue|Trigonometric funcs. I/O|m_trigonometricBehaviour|When using trigonometric or arc-functions as per the "Operation"-keyvalue, this is used to determine what your input/desired output measure is. You'll usually want to stick to degrees.}}
 +
{{Entity_keyvalue|Append spaces (for strings)|m_iAppendSpaces|When the destination keyvalue is a string, this specifies how many spaces to append after the operations. You'll usually want to use this with either the "Replace"- or "Append"-operation. This was implemented because Valve Hammer Editor omits any trailing spaces in keyvalues (but not leading ones).}}
 
{{Entity_keyvalue|Trigger after operation|message|Set entity/entities to be triggered after the trigger_changevalue has set the new keyvalue, by targetname as usual.  
 
{{Entity_keyvalue|Trigger after operation|message|Set entity/entities to be triggered after the trigger_changevalue has set the new keyvalue, by targetname as usual.  
 
This is very useful when you need a chain of operations to happen in a specific order and without any delay in between.}}
 
This is very useful when you need a chain of operations to happen in a specific order and without any delay in between.}}
Line 26: Line 29:
 
== Notes ==
 
== Notes ==
  
Trigger_changevalue supports the use of "!activator" and "!caller" in the "Destination Entity"-field.Trying to write a vector to a float or integer will cause the vector's length to be written. This is in respect to any ignored dimensions as per spawnflags.
+
* Trigger_changevalue supports the use of "!activator" and "!caller" in the "Destination Entity" field.
 +
* Trying to write a vector to a float or integer will cause the vector's length to be written. This is in respect to any ignored dimensions as per <code>spawnflags</code>.
 +
 
 +
== Issues ==
 +
trigger_changetarget only changes the target of one entity, the first one it can find, if there are several entities of the same name that the changetarget targets - trigger_changevalue can update multiple entities at the same time if they share the same name, so this can be used instead.
 +
<br> This is fixed in 5.26.
  
  

Latest revision as of 20:35, 28 May 2023

trigger_changevalue
Type

point

Status

supported

 


Trigger_changevalue can perform arithmetic and logic operations on base-keyvalues of entities, as well as replace their private keyvalues. See trigger_copyvalue for a variant of this with more options. Supports custom keyvalues.

1 Keyvalues

Destination Entity : target

Name of the entity which's keyvalue is to changed. This can refer to more than one.

Destination Keyvalue : m_iszValueName

Name of the key which's value is to be changed.

Static source-value : m_iszNewValue

Value to be applied to the destination keyvalue.

Operation : m_iszValueType

Trigonometric funcs. I/O : m_trigonometricBehaviour

When using trigonometric or arc-functions as per the "Operation"-keyvalue, this is used to determine what your input/desired output measure is. You'll usually want to stick to degrees.

Append spaces (for strings) : m_iAppendSpaces

When the destination keyvalue is a string, this specifies how many spaces to append after the operations. You'll usually want to use this with either the "Replace"- or "Append"-operation. This was implemented because Valve Hammer Editor omits any trailing spaces in keyvalues (but not leading ones).

Trigger after operation : message

Set entity/entities to be triggered after the trigger_changevalue has set the new keyvalue, by targetname as usual. This is very useful when you need a chain of operations to happen in a specific order and without any delay in between.

2 Flags

1 : Don't use X

When using vectors/arrays, this will ignore the first array. E.g., when setting render-color, specifying this flag would ignore the 'Red'-value.

2 : Don't use Y

When using vectors/arrays, this will ignore the second array. E.g., when setting angles, specifying this flag would ignore the 'Yaw'-value.

4 : Don't use Z

When using vectors/arrays, this will ignore the third array. E.g., when setting velocity, specifying this flag would ignore the vertical velocity.

32 : Invert target value

The destination keyvalue will be multiplied with minus one before proceeding.

64 : Invert source value

The source-value will be multiplied with minus one before proceeding; this change is only temporary and this keyvalue is rather useless, as you can always prepend a minus-sign to the static source-value.

3 Notes

  • Trigger_changevalue supports the use of "!activator" and "!caller" in the "Destination Entity" field.
  • Trying to write a vector to a float or integer will cause the vector's length to be written. This is in respect to any ignored dimensions as per spawnflags.

4 Issues

trigger_changetarget only changes the target of one entity, the first one it can find, if there are several entities of the same name that the changetarget targets - trigger_changevalue can update multiple entities at the same time if they share the same name, so this can be used instead.
This is fixed in 5.26.