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: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
Note:For other VScript keyvalues notable for this entity like vscripts, thinkfunction and inputs like RunScriptCode, CallScriptFunction see Generic Keyvalues, Inputs and Outputs 
		
	
|  (-default kv template) | SirYodaJedi (talk | contribs)  | ||
| (19 intermediate revisions by 7 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| | {{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 Targetname}} | {{KV Targetname}} | ||
| {{KV|EntityGroup[0]|intn=Group00|to=EntityGroup[15]|intn2=Group15|target_destination| | {{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 | ||
| [[Category:Mapbase  | <!-- 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]] | |||
| [[Category:Half-Life Deathmatch: Source entities]] | |||
| [[Category:Half-Life Deathmatch: Source logical entities]] | |||
| [[Category:Counter-Strike: Source entities]] | |||
| [[Category:Counter-Strike: Source logical entities]] | |||
| [[Category:Day of Defeat: Source entities]] | |||
| [[Category:Day of Defeat: Source logical entities]] | |||
Latest revision as of 10:44, 26 October 2025
|  Class hierarchy | 
|---|
| CLogicScript | 
|  logicentities.cpp | 
logic_script  is a   logical entity  available in all  Source games since
 Source games since  Left 4 Dead 2. It is also available in the
 Left 4 Dead 2. It is also available in the  Team Fortress 2 branch and
 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:This entity counts as an edict, not a logical entity as one would expect.
Note: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 where- EntityGroup[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 (for- i < EntityGroup.len()), then- EntityGroup[i]is- null.
- MyEntityGroup(not in ): a table which contains the handles with keys being the names, for example if the EntityGroup[2] keyvalue is set to ): a table which contains the handles with keys being the names, for example if the EntityGroup[2] keyvalue is set to- sound.start, then- MyEntityGroup["sound.start"] == EntityGroup[2].
- MyEntityGroupArray(not in ): an array which is the same as ): 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. - __AppendToScriptGroupis then called with each name specified by- Group00-- 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:For other VScript keyvalues notable for this entity like vscripts, thinkfunction and inputs like RunScriptCode, CallScriptFunction see Generic Keyvalues, Inputs and Outputs
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
External links
- It's the VScripting documentation FAQ! (Steam Forums)
- Scripting for Left 4 Dead 2 (Leeland.net) - Example uses of logic_script
Categories: 
- Source
- Source 2
- CPointEntity
- Logical entities
- Source base entities
- Source base logical entities
- Mapbase entities
- Mapbase logical entities
- Team Fortress 2 entities
- Team Fortress 2 logical entities
- Half-Life 2: Deathmatch entities
- Half-Life 2: Deathmatch logical entities
- Half-Life Deathmatch: Source entities
- Half-Life Deathmatch: Source logical entities
- Counter-Strike: Source entities
- Counter-Strike: Source logical entities
- Day of Defeat: Source entities
- Day of Defeat: Source logical entities





























