Scripting:Targeting: Difference between revisions

Building pieces of another world.
Jump to navigation Jump to search
gravatar The Watcher [userbureaucratsysopPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs)
No edit summary
gravatar The Watcher [userbureaucratsysopPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs)
No edit summary
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Target syntax ==
== Target syntax ==
This page shows all the possible forms of value you can specify for a <code>target</code> type parameter. If you have used NVScript most of the possible forms will be familiar to you, although TWScript adds a few new features. Wherever possible I've tried to replicate the syntax used by NVScript for editor convenience.


This page shows all the possible forms of value you can specify for a <code>target</code> type parameter. The values supported by a given script will vary depending on the situation, and sometimes it may not make much sense to use a given value even if the script does not explicitly prohibit it. In general the script documentation will indicate which values are likely to be appropriate.
Sometimes it may not make much sense to use a given targeting form, even if the script does not explicitly prohibit it. In general the script documentation will indicate which values are likely to be appropriate if it matters.


; <code>parameter=[me]</code>
; <code>parameter=[me]</code>
Line 9: Line 10:
: All actions taken by scripts happen in response to messages received by the object the script is attached to. This option allows the script to target the object that sent the message that is currently being handled by the script. Note that this should be used with caution
: All actions taken by scripts happen in response to messages received by the object the script is attached to. This option allows the script to target the object that sent the message that is currently being handled by the script. Note that this should be used with caution


; <code>parameter=*''archetype''</code>
; <code>parameter=*<span class="param">archetype</span></code>
: Targets all direct concrete descendants of the specified archetype. So, for example, <code>parameter=*Chest</code> will target all concrete Chest objects in your level, but ''not'' any concrete Safe, VicHopeChest, LC_Chest, or other indirect descendants of the Chest archetype.
: Targets all direct concrete descendants of the specified archetype. So, for example, <code>parameter=*<span class="param">Chest</span></code> will target all concrete Chest objects in your level, but ''not'' any concrete Safe, VicHopeChest, LC_Chest, or other indirect descendants of the Chest archetype.


; <code>parameter=@''archetype''</code>
; <code>parameter=@<span class="param">archetype</span></code>
: Targets all direct or indirect concrete descendants of the specified archetype. For example, <code>parameter=@Chest</code> will target all concrete Chest objects in your level ''and'' any concrete Safe, VicHopeChest, or other indirect descendants of the Chest archetype.
: Targets all direct or indirect concrete descendants of the specified archetype. For example, <code>parameter=@<span class="param">Chest</span></code> will target all concrete Chest objects in your level ''and'' any concrete Safe, VicHopeChest, or other indirect descendants of the Chest archetype.


; <code>parameter=<''distance'':''archetype''</code> or <code>parameter=>''distance'':''archetype''</code>
; <code>parameter=&lt;<span class="param">distance</span>:<span class="param">archetype</span></code> or <code>parameter=&gt;<span class="param">distance</span>:<span class="param">archetype</span></code>
: Targets all descendants of the specified archetype that are less than (<code>&lt;</code> version) or greater than (<code>&gt;</code> version) the specified distance from the script's host object. Distances are given in Dromed units, and may be decimal values. For example, <code>parameter=<5.3:Chest</code> will target all direct and indirect concrete descendants of the Chest archetype that are less than 5.3 Dromed units from the script host object. By default, all direct or indirect concrete descendants are targeted, however you can include <code>*</code> before the archetype name to restrict the targeting to direct descendants only, eg: <code>parameter=<5.3:*Chest</code> will target '''only''' concrete Chest objects within 5.3 Dromed units, not including concrete Safe, VicHopeChest or other indirect concrete descendants of Chest.
: Targets all descendants of the specified archetype that are less than (<code>&lt;</code> version) or greater than (<code>&gt;</code> version) the specified distance from the script's host object. Distances are given in Dromed units, and may be decimal values. For example, <code>parameter=&lt;<span class="param">5.3</span>:<span class="param">Chest</span></code> will target all direct and indirect concrete descendants of the Chest archetype that are less than 5.3 Dromed units from the script host object. By default, all direct or indirect concrete descendants are targeted, however you can include <code>*</code> before the archetype name to restrict the targeting to direct descendants only, eg: <code>parameter=&lt;<span class="param">5.3</span>:<span class="param">*Chest</span></code> will target '''only''' concrete Chest objects within 5.3 Dromed units, not including concrete Safe, VicHopeChest or other indirect concrete descendants of Chest.


; <code>parameter=&''linkdef''</code>
; <code>parameter=&<span class="param">linkdef</span></code>
: Targets objects linked to the script host object based on the specified link definition. The syntax for the link definition is given in the next section.
: Targets objects linked to the script host object based on the specified link definition. The syntax for the link definition is given in the next section.


== Link definition syntax ==
== Link definition syntax ==
The link definition syntax is complicated enough to need its own section! In its most simple form, you provide the name of a link and all objects linked to the host object by links of that type are targeted. However, that only scratches the surface of the possibilities.


; <code>parameter=&<span class="param">linktype</span></code>
: Objects linked to the script host object via links of the specified link type will be targeted. For example, <code>parameter=&<span class="param">ControlDevice</span></code> will target ControlDevice linked objects. By default all linked objects will be targeted, but that behaviour can be changed using the options discussed below.
A number of additional 'sigils' can be placed between the <code>&</code> and the <code><span class="param">linktype</span></code> to provide more advanced features. In general the order in which sigils are specified does not matter, as long as they appear between the <code>&</code> and the <code><span class="param">linktype</span></code> they will be picked up and acted upon, but some only make sense when combined with others.
=== Supported sigils ===
; <code>?</code>
: Including <code>?</code> as a sigil turns on random selection mode. If this is specified then the the targeted object or objects will be chosen at random from the objects linked to the script host object by the specified link type. By default only a single object will be chosen at random, however this can be changed using the <code>[]</code> and <code>!</code> sigils
; <code>%</code>
: Including the <code>%</code> sigil will restrict the objects targeted to archetypes only. For example, <code>parameter=&<span class="param">%ScriptParams</span></code> will only target archetypes linked to the script host object with ScriptParams links.
; <code>#</code>
: Effectively the inverse of the previous sigil, including the <code>#</code> sigil will restrict the objects targeted to concrete objects only. For example, <code>parameter=&<span class="param">#ScriptParams</span></code> will only target concrete objects linked to the script host object with ScriptParams links. Note that if both <code>%</code> and <code>#</code> appear in the link definition, the last specified one takes priority.
; <code>[<span class="param">count</span>]</code>
: You can control the number of objects targeted by prefixing the link type with the desired maximum count in square brackets <code>[ ]</code>. If the specified count is larger than the number of linked objects, the number of objects targeted will be the number of linked objects. For example <code>parameter=&[<span class="param">4</span>]<span class="param">ControlDevice</span></code> will target at most the first four objects linked to the script host object by ControlDevice links. If only two objects are linked by ControlDevice links, only those two objects will be targeted. The behaviour of this sigil depends on whether random (or weighted random) mode is enabled or not:
:* If random and weighted random mode are not enabled, the order of the objects selected is based on the link IDs from the host object to the linked objects. If there are more linked objects than the specified count, this will always select the same subset of the linked objects.
:* If random mode (but '''not''' weighted random mode) is enabled, the list of linked objects is shuffled into a random order and at most <code>count</code> objects are selected from that list. Objects will not appear more than once provided that they are only linked to the host object once.
:* If weighted random mode is enabled, this will always target <code>count</code> randomly selected linked objects, potentially selecting the same object multiple times. In general you should avoid using <code>[]</code> in weighted random mode unless the script documentation indicates that doing so is safe/sensible/not likely to open a class 4 gate to the Sleeper's Pyramid on the Dead Plateau.
; <code>!</code>
: Target all linked objects. This is the default when random mode is off and <code>[ ]</code> has not been specified, and if <code>!</code> and <code>[ ]</code> appear in the linkdef, <code>!</code> will take priority. When random mode (but '''not''' weighted random mode) is enabled, <code>!</code> will return all the linked objects in a random order, guaranteeing that each object only appears once provided that they are only linked to the host object once.
=== Weighted random mode ===
If <span class="param">linkdef</span> is set to <code>Weighted</code> (ie: <code>parameter=&<span class="param">Weighted</span></code>) a special 'weighted random mode' is enabled. This mode looks at the ScriptParams links from the host object to other objects, and uses the script data set for the ScriptParams links to determine which links (and hence, which objects) are more likely to be selected than others when choosing at random. So, a link with data of 2 will be chosen twice as often as one with data of 1. If the data is not set for a ScriptParams link, or the data is not a number, its weight defaults to 1. The <code>%</code>, <code>#</code>, and <code>[]</code> sigils may be be used with weighted random mode, but <code>!</code> is ignored (as it makes no sense in this situation) and <code>?</code> is enabled implicitly.


{{Scripting:Navbox}}
{{Scripting:Navbox}}
{{:Site Navigation}}
{{:Site Navigation}}
<references />
<references />

Revision as of 23:45, 20 June 2014

Target syntax

This page shows all the possible forms of value you can specify for a target type parameter. If you have used NVScript most of the possible forms will be familiar to you, although TWScript adds a few new features. Wherever possible I've tried to replicate the syntax used by NVScript for editor convenience.

Sometimes it may not make much sense to use a given targeting form, even if the script does not explicitly prohibit it. In general the script documentation will indicate which values are likely to be appropriate if it matters.

parameter=[me]
Targets the object the script is attached to.
parameter=[source]
All actions taken by scripts happen in response to messages received by the object the script is attached to. This option allows the script to target the object that sent the message that is currently being handled by the script. Note that this should be used with caution
parameter=*archetype
Targets all direct concrete descendants of the specified archetype. So, for example, parameter=*Chest will target all concrete Chest objects in your level, but not any concrete Safe, VicHopeChest, LC_Chest, or other indirect descendants of the Chest archetype.
parameter=@archetype
Targets all direct or indirect concrete descendants of the specified archetype. For example, parameter=@Chest will target all concrete Chest objects in your level and any concrete Safe, VicHopeChest, or other indirect descendants of the Chest archetype.
parameter=<distance:archetype or parameter=>distance:archetype
Targets all descendants of the specified archetype that are less than (< version) or greater than (> version) the specified distance from the script's host object. Distances are given in Dromed units, and may be decimal values. For example, parameter=<5.3:Chest will target all direct and indirect concrete descendants of the Chest archetype that are less than 5.3 Dromed units from the script host object. By default, all direct or indirect concrete descendants are targeted, however you can include * before the archetype name to restrict the targeting to direct descendants only, eg: parameter=<5.3:*Chest will target only concrete Chest objects within 5.3 Dromed units, not including concrete Safe, VicHopeChest or other indirect concrete descendants of Chest.
parameter=&linkdef
Targets objects linked to the script host object based on the specified link definition. The syntax for the link definition is given in the next section.

Link definition syntax

The link definition syntax is complicated enough to need its own section! In its most simple form, you provide the name of a link and all objects linked to the host object by links of that type are targeted. However, that only scratches the surface of the possibilities.

parameter=&linktype
Objects linked to the script host object via links of the specified link type will be targeted. For example, parameter=&ControlDevice will target ControlDevice linked objects. By default all linked objects will be targeted, but that behaviour can be changed using the options discussed below.

A number of additional 'sigils' can be placed between the & and the linktype to provide more advanced features. In general the order in which sigils are specified does not matter, as long as they appear between the & and the linktype they will be picked up and acted upon, but some only make sense when combined with others.

Supported sigils

?
Including ? as a sigil turns on random selection mode. If this is specified then the the targeted object or objects will be chosen at random from the objects linked to the script host object by the specified link type. By default only a single object will be chosen at random, however this can be changed using the [] and ! sigils
%
Including the % sigil will restrict the objects targeted to archetypes only. For example, parameter=&%ScriptParams will only target archetypes linked to the script host object with ScriptParams links.
#
Effectively the inverse of the previous sigil, including the # sigil will restrict the objects targeted to concrete objects only. For example, parameter=&#ScriptParams will only target concrete objects linked to the script host object with ScriptParams links. Note that if both % and # appear in the link definition, the last specified one takes priority.
[count]
You can control the number of objects targeted by prefixing the link type with the desired maximum count in square brackets [ ]. If the specified count is larger than the number of linked objects, the number of objects targeted will be the number of linked objects. For example parameter=&[4]ControlDevice will target at most the first four objects linked to the script host object by ControlDevice links. If only two objects are linked by ControlDevice links, only those two objects will be targeted. The behaviour of this sigil depends on whether random (or weighted random) mode is enabled or not:
  • If random and weighted random mode are not enabled, the order of the objects selected is based on the link IDs from the host object to the linked objects. If there are more linked objects than the specified count, this will always select the same subset of the linked objects.
  • If random mode (but not weighted random mode) is enabled, the list of linked objects is shuffled into a random order and at most count objects are selected from that list. Objects will not appear more than once provided that they are only linked to the host object once.
  • If weighted random mode is enabled, this will always target count randomly selected linked objects, potentially selecting the same object multiple times. In general you should avoid using [] in weighted random mode unless the script documentation indicates that doing so is safe/sensible/not likely to open a class 4 gate to the Sleeper's Pyramid on the Dead Plateau.
!
Target all linked objects. This is the default when random mode is off and [ ] has not been specified, and if ! and [ ] appear in the linkdef, ! will take priority. When random mode (but not weighted random mode) is enabled, ! will return all the linked objects in a random order, guaranteeing that each object only appears once provided that they are only linked to the host object once.

Weighted random mode

If linkdef is set to Weighted (ie: parameter=&Weighted) a special 'weighted random mode' is enabled. This mode looks at the ScriptParams links from the host object to other objects, and uses the script data set for the ScriptParams links to determine which links (and hence, which objects) are more likely to be selected than others when choosing at random. So, a link with data of 2 will be chosen twice as often as one with data of 1. If the data is not set for a ScriptParams link, or the data is not a number, its weight defaults to 1. The %, #, and [] sigils may be be used with weighted random mode, but ! is ignored (as it makes no sense in this situation) and ? is enabled implicitly.


Authors

  • gravatar The Watcher [userbureaucratsysopPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+]