logic_script
From Valve Developer Community
Jump to navigation
Jump to search
English (en)中文 (zh) Translate (Translate)
Deutsch (de) Esperanto (eo) Español (es) Français (fr) Suomi (fi) Hrvatski (hr) Magyar (hu) Italiano (it) 日本語 (ja) 한국어 (ko) Nederlands (nl) Polski (pl) Português (pt) Português do Brasil (pt-br) Русский (ru) Slovenčina (sk) Svenska (sv) Türkçe (tr) Українська (uk) Tiếng Việt (vi) 中文(臺灣) (zh-tw) Translationmark (TranslationMark) Flag-white-i.png
| C++ Class hierarchy |
|---|
| CLogicScript |
| C++ logicentities.cpp |
logic_script is a logical entity available in all Source Source games since Left 4 Dead 2 Left 4 Dead 2 . It is also available in the Team Fortress 2 branch Team Fortress 2 branch and Mapbase 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.
Note.pngNote:This entity counts as an edict, not a logical entity as one would expect.
KeyValues
- Name (targetname) <string>[ Edit ]
- The name that other entities refer to this entity by, via Inputs/Outputs or other keyvalues (e.g.
parentnameortarget).
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 Counter-Strike: Global Offensive ): a table which contains the handles with keys being the names, for example if the EntityGroup[2] keyvalue is set tosound.start, thenMyEntityGroup["sound.start"] == EntityGroup[2].MyEntityGroupArray(not in Counter-Strike: Global Offensive ): an array which is the same asEntityGroup.
-
VScript run internally to achieve this
The following VScript is run in logic_script scope when it spawns.
__AppendToScriptGroupis then called with each name specified byGroup00-Group15keyvalues.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; } } }
Note.pngNote:For other VScript keyvalues notable for this entity like vscripts, thinkfunction and inputs like RunScriptCode, CallScriptFunction see Generic Keyvalues, Inputs and Outputs
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