Logic script: Difference between revisions
Jump to navigation
Jump to search
Note:This entity counts as an edict, not a logical entity as one would expect.
Note:For other VScript keyvalues notable for this entity like vscripts, thinkfunction and inputs like RunScriptCode, CallScriptFunction see Generic Keyvalues, Inputs and Outputs
mNo edit summary |
(Undo revision 484850 by WoShiGeNiCheng (talk)) Tag: Undo |
||
(24 intermediate revisions by 12 users not shown) | |||
Line 1: | Line 1: | ||
{{Source topicon}} {{Source 2 topicon}} | {{LanguageBar}} {{Source topicon}} {{Source 2 topicon}} | ||
{{ | {{tabsBar|main=s2|base=logic_script}} | ||
{{CD|CLogicScript|CPointEntity|file1=1}} __NOTOC__ | |||
[[File:Logic_script.png|left|Source 1 editor sprite]] | [[File:Logic_script.png|left|Source 1 editor sprite]] | ||
[[File:Logic_script_src2.png|left|Source 2 editor sprite]] | [[File:Logic_script_src2.png|left|Source 2 editor sprite]] | ||
{{ | {{this is a|logical entity|name=logic_script|since=Left 4 Dead 2}} It is also available in the {{tf2branch|4}} and {{mapbase|4}}. | ||
This entity functions as a container for [[VScript]]s. In Left 4 Dead 2, for example, it is used extensively for the logic in "carnival games" found in the Dark Carnival campaign, such as ''Peanut Gallery'', ''Strongman Contest'', ''Whack-a-Stach'', etc. | |||
{{note|This entity counts as an [[edict_t|edict]], not a logical entity as one would expect.}} | |||
{{clr}} | {{clr}} | ||
== KeyValues == | == KeyValues == | ||
{{KV | {{KV Targetname}} | ||
{{KV | {{KV|EntityGroup[0]|intn=Group00|to=EntityGroup[15]|intn2=Group15|target_destination | ||
|3=Targetnames of entities to make them accessible in Squirrel code. All specified entity names will be searched for upon this entity spawning and their [[VScript Fundamentals#Script Handles|script handles]] are added to this <code>logic_script</code>'s script scope: | |||
{{ | :*<code>EntityGroup</code>: an array where <code>EntityGroup[0]</code> is the handle of an entity with the name specified in the '''EntityGroup[0]''' keyvalue etc. If multiple entities exist with that name, the first handle found is used. The array length is the highest non-empty EntityGroup index that is not empty plus one, so in Squirrel code, be sure to not hardcode indices if the length is uncertain. If the keyvalue '''EntityGroup[i]''' is the empty string (for <code>i < EntityGroup.len()</code>), then <code>EntityGroup[i]</code> is <code>null</code>. | ||
:*<code>MyEntityGroup</code> {{csgo|not}}: a table which contains the handles with keys being the names, for example if the '''EntityGroup[2]''' keyvalue is set to <code>sound.start</code>, then <code>MyEntityGroup["sound.start"] == EntityGroup[2]</code>. | |||
:*<code>MyEntityGroupArray</code> {{csgo|not}}: an array which is the same as <code>EntityGroup</code>. | |||
:{{expand|title=VScript run internally to achieve this| | |||
The following VScript is run in logic_script scope when it spawns. <code>__AppendToScriptGroup</code> is then called with each name specified by <code>Group00</code>-<code>Group15</code> keyvalues. | |||
<syntaxhighlight lang=js>EntityGroup <- []; | |||
MyEntityGroup <- {}; | |||
MyEntityGroupArray <- EntityGroup; | |||
function __AppendToScriptGroup( name ) | |||
{ | |||
if ( name.len() == 0 ) | |||
{ | |||
EntityGroup.append( null ); | |||
} | |||
else | |||
{ | |||
local ent = Entities.FindByName( null, name ); | |||
EntityGroup.append( ent ); | |||
if ( ent != null ) | |||
{ | |||
ent.ValidateScriptScope(); | |||
MyEntityGroup[name] <- ent; | |||
ent.GetScriptScope().EntityGroup <- EntityGroup; | |||
} | |||
} | |||
}</syntaxhighlight> | |||
}}}} | |||
{{ | {{note|For other VScript keyvalues notable for this entity like '''vscripts''', '''thinkfunction''' and inputs like '''RunScriptCode''', '''CallScriptFunction''' see [[Generic Keyvalues, Inputs and Outputs]] }} | ||
== See also == | == See also == | ||
* [[L4D2 | * [[L4D2 VScripts]] | ||
* [[Left 4 Dead 2 Tool Updates]] | * [[Left 4 Dead 2 Tool Updates]] | ||
== External links == | == External links == | ||
* [https://web.archive.org/web/20170524163422/http://forums.steampowered.com/forums/showthread.php?t=1238461 It's the | * [https://web.archive.org/web/20170524163422/http://forums.steampowered.com/forums/showthread.php?t=1238461 It's the VScripting documentation FAQ! (Steam Forums)] | ||
* [http://leeland.stores.yahoo.net/l4d2-scripting.html Scripting for Left 4 Dead 2 (Leeland.net)] - Example uses of logic_script | * [http://leeland.stores.yahoo.net/l4d2-scripting.html Scripting for Left 4 Dead 2 (Leeland.net)] - Example uses of logic_script | ||
<!-- for cats not added by {{this is a}} template --> | |||
[[Category:Mapbase entities]] | |||
[[Category:Mapbase logical entities]] | |||
[[Category:Team Fortress 2 entities]] | |||
[[Category:Team Fortress 2 logical entities]] | |||
[[Category:Half-Life 2: Deathmatch entities]] | |||
[[Category:Half-Life 2: Deathmatch logical entities]] |
Latest revision as of 01:45, 5 July 2025
![]() |
---|
CLogicScript |
![]() |
logic_script
is a logical entity available in all Source games since
Left 4 Dead 2. It is also available in the
Team Fortress 2 branch and
Mapbase.
This entity functions as a container for VScripts. In Left 4 Dead 2, for example, it is used extensively for the logic in "carnival games" found in the Dark Carnival campaign, such as Peanut Gallery, Strongman Contest, Whack-a-Stach, etc.

KeyValues
- Name (targetname) <string>[ Edit ]
- The name that other entities refer to this entity by, via Inputs/Outputs or other keyvalues (e.g.
parentname
ortarget
).
Also displayed in Hammer's 2D views and Entity Report.See also: Generic Keyvalues, Inputs and Outputs available to all entities
- EntityGroup[0] (Group00) to EntityGroup[15] (Group15) <targetname>
- Targetnames of entities to make them accessible in Squirrel code. All specified entity names will be searched for upon this entity spawning and their script handles are added to this
logic_script
's script scope:EntityGroup
: an array whereEntityGroup[0]
is the handle of an entity with the name specified in the EntityGroup[0] keyvalue etc. If multiple entities exist with that name, the first handle found is used. The array length is the highest non-empty EntityGroup index that is not empty plus one, so in Squirrel code, be sure to not hardcode indices if the length is uncertain. If the keyvalue EntityGroup[i] is the empty string (fori < EntityGroup.len()
), thenEntityGroup[i]
isnull
.MyEntityGroup
(not in): a table which contains the handles with keys being the names, for example if the EntityGroup[2] keyvalue is set to
sound.start
, thenMyEntityGroup["sound.start"] == EntityGroup[2]
.MyEntityGroupArray
(not in): an array which is the same as
EntityGroup
.
VScript run internally to achieve this The following VScript is run in logic_script scope when it spawns.
__AppendToScriptGroup
is then called with each name specified byGroup00
-Group15
keyvalues.EntityGroup <- []; MyEntityGroup <- {}; MyEntityGroupArray <- EntityGroup; function __AppendToScriptGroup( name ) { if ( name.len() == 0 ) { EntityGroup.append( null ); } else { local ent = Entities.FindByName( null, name ); EntityGroup.append( ent ); if ( ent != null ) { ent.ValidateScriptScope(); MyEntityGroup[name] <- ent; ent.GetScriptScope().EntityGroup <- EntityGroup; } } }

See also
External links
- It's the VScripting documentation FAQ! (Steam Forums)
- Scripting for Left 4 Dead 2 (Leeland.net) - Example uses of logic_script