Context: Difference between revisions
(Update the overall info about Contexts and add Context Value Operations section) |
|||
Line 1: | Line 1: | ||
[[Category:AI Programming]] | [[Category:AI Programming]] | ||
{{stub}} | {{stub}} | ||
Map placed entities have | Map placed entities can have contexts assigned to them via '''ResponseContext''' keyvalue or '''AddContext''' input or via other means. They take the form: | ||
<pre> | <pre><key>:<value>[:<expirationTime>][,<key2>:<value2>[:<expirationTime2>]]</pre> | ||
Where '''<key>:<value>''' is a minimal requirement for the context to be added and '''[:<expirationTime>]''' is an optional float value which tells when to expire the context in seconds, default is 0 which means no expiration time. You can also provide multiple contexts in one go by comma separating them. | |||
{{ModernNote|Context value could be of any type and is stored as string, but some entities expect value to be of a specific type, like [[filter_activator_context]] expects the value to be integer only.}} | |||
{{ModernNote|Expiration is only triggered on response dispatches.}} | |||
==Context Value Operations== | |||
Contexts provide a way to modify already stored context value. There are 4 available operations: | |||
*'''Copy''' : '''(default operation)''' Copies the contents of the new value in place of the old one. | |||
*'''Increment''' : '''++<amount>''' Increments the stored value by the provided '''amount'''. | |||
*'''Decrement''' : '''--<amount>''' Decrements the stored value by the provided '''amount'''. | |||
*'''Toggle''' : '''!''' Inverts the truthfulness of the stored value, the end result value would be either 0 or 1. | |||
{{ModernNote|'''Increment/Decrement/Toggle''' operations do expect the value to be of an integer type.}} | |||
{{ModernNote|'''Increment/Decrement/Toggle''' operations would assume stored value is 0 if no context existed before the operation.}} | |||
{{ModernNote|'''Increment/Decrement''' require the '''amount''' value to be provided and to be of an integer type, otherwise the action would not be performed.}} | |||
Examples of such operations: | |||
*Incrementing the value by 5 of context '''contextName''': | |||
:<pre>contextName:++5</pre> | |||
*Toggling the value of context '''contextName''': | |||
:<pre>contextName:!</pre> | |||
==Context Usage== | |||
When an entity with any such context keypairs is asked to dispatch a [[Responses|response]], the keypairs are added to the [[Criteria]] set passed to the [[Rules]] system. Thus, map placed entities and triggers can specify their own context keypairs and these can be hooked up to response rules to do map-specific and appropriate responses. | When an entity with any such context keypairs is asked to dispatch a [[Responses|response]], the keypairs are added to the [[Criteria]] set passed to the [[Rules]] system. Thus, map placed entities and triggers can specify their own context keypairs and these can be hooked up to response rules to do map-specific and appropriate responses. | ||
Line 26: | Line 47: | ||
==Related Entities== | ==Related Entities== | ||
*[[worldspawn]] | *[[worldspawn]] | ||
* | *CBaseEntity | ||
**KeyValue: | **KeyValue: | ||
***ResponseContext(string) : "Response Contexts" : "" : "Response system context(s) for this entity | ***ResponseContext(string) : "Response Contexts" : "" : "Response system context(s) for this entity. When this entity speaks, the context(s) will be passed to the response rules system." | ||
**Input | **Input | ||
*** AddContext(string) : "Adds a context to this entity's list of response contexts | ***AddContext(string) : "Adds a context to this entity's list of response contexts." | ||
***RemoveContext(string) : "Remove a context from this entity's list of response contexts. The name should match the 'key' of a previously added context." | ***RemoveContext(string) : "Remove a context from this entity's list of response contexts. The name should match the 'key' of a previously added context." | ||
***ClearContext(void) : "Removes all contexts in this entity's list of response contexts." | ***ClearContext(void) : "Removes all contexts in this entity's list of response contexts." |
Revision as of 06:25, 28 June 2023
Map placed entities can have contexts assigned to them via ResponseContext keyvalue or AddContext input or via other means. They take the form:
<key>:<value>[:<expirationTime>][,<key2>:<value2>[:<expirationTime2>]]
Where <key>:<value> is a minimal requirement for the context to be added and [:<expirationTime>] is an optional float value which tells when to expire the context in seconds, default is 0 which means no expiration time. You can also provide multiple contexts in one go by comma separating them. Template:ModernNote Template:ModernNote
Context Value Operations
Contexts provide a way to modify already stored context value. There are 4 available operations:
- Copy : (default operation) Copies the contents of the new value in place of the old one.
- Increment : ++<amount> Increments the stored value by the provided amount.
- Decrement : --<amount> Decrements the stored value by the provided amount.
- Toggle : ! Inverts the truthfulness of the stored value, the end result value would be either 0 or 1.
Template:ModernNote Template:ModernNote Template:ModernNote
Examples of such operations:
- Incrementing the value by 5 of context contextName:
contextName:++5
- Toggling the value of context contextName:
contextName:!
Context Usage
When an entity with any such context keypairs is asked to dispatch a response, the keypairs are added to the Criteria set passed to the Rules system. Thus, map placed entities and triggers can specify their own context keypairs and these can be hooked up to response rules to do map-specific and appropriate responses.
For example, there is a npc_citizen with ResponseContext keyvalue is "customs_queue:1" in sdk_d1_trainstation_01.vmf.
This context will match the following criterion from script/talker/npc_citizen_terminal.txt
:
criterion "IsTerminalCustomsQueue" "customs_queue" "1" required
And then according to this rule, response CitizenCustomsQueue would be chosen.
rule CitizenCustomsQueue { criteria IsCitizen ConceptTalkUse IsTerminalCustomsQueue NPCIdle response CitizenCustomsQueue }
Related Entities
- worldspawn
- CBaseEntity
- KeyValue:
- ResponseContext(string) : "Response Contexts" : "" : "Response system context(s) for this entity. When this entity speaks, the context(s) will be passed to the response rules system."
- Input
- AddContext(string) : "Adds a context to this entity's list of response contexts."
- RemoveContext(string) : "Remove a context from this entity's list of response contexts. The name should match the 'key' of a previously added context."
- ClearContext(void) : "Removes all contexts in this entity's list of response contexts."
- KeyValue:
- env_speaker (this can have a script file containing rules for playing appropriate sounds.)
- ai_speechfilter
- filter_activator_context (allow filtering based on the contexts of an entity)