This article's documentation is for anything that uses the Source engine. Click here for more information.
This article's documentation is for Source 2. Click here for more information.

Logic script: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (Indented Expand and removed its margin_left.)
Line 15: Line 15:
{{KV|EntityGroup[0]|intn=Group00|to=EntityGroup[15]|intn2=Group15|target_destination|All specified entity names will be searched for upon this entity spawning and their [[VScript_Fundamentals#Script_Handles|script handles]] are added to an array named <code>EntityGroup</code> in <code>logic_script</code>'s script scope. <code>EntityGroup[0]</code> contains handle of entity with name specified in '''EntityGroup[0]''' property etc. If multiple entities with the given named exists, handle of first found will be used.
{{KV|EntityGroup[0]|intn=Group00|to=EntityGroup[15]|intn2=Group15|target_destination|All specified entity names will be searched for upon this entity spawning and their [[VScript_Fundamentals#Script_Handles|script handles]] are added to an array named <code>EntityGroup</code> in <code>logic_script</code>'s script scope. <code>EntityGroup[0]</code> contains handle of entity with name specified in '''EntityGroup[0]''' property etc. If multiple entities with the given named exists, handle of first found will be used.
:Table <code>MyEntityGroup</code> is also created which contains the handles with keys being the names. (for some reason there is also <code>MyEntityGroupArray</code> which is same as <code>EntityGroup</code>)
:Table <code>MyEntityGroup</code> is also created which contains the handles with keys being the names. (for some reason there is also <code>MyEntityGroupArray</code> which is same as <code>EntityGroup</code>)
{{expand|margin_left=2em|title=Vscript run internally to achieve this|
:{{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.
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 <- [];
<syntaxhighlight lang=js>EntityGroup <- [];
MyEntityGroup <- {};
MyEntityGroup <- {};
Line 41: Line 41:




{{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 ==
== See also ==
* [[L4D2 Vscripts]]
* [[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 vscripting documentation FAQ! (Steam Forums)]
* [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



Revision as of 00:22, 18 January 2025

English (en)中文 (zh)Translate (Translate)
C++ Class hierarchy
CLogicScript
CPointEntity
CBaseEntity
Source 1 editor sprite
Source 2 editor sprite

logic_script is a point entity available in all Source Source games since Left 4 Dead 2 Left 4 Dead 2. It is also available in 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.

KeyValues

Name (targetname) <string>[ Edit ]
The name that other entities refer to this entity by, via Inputs/Outputs or other keyvalues (e.g. parentname or target).
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>
All specified entity names will be searched for upon this entity spawning and their script handles are added to an array named EntityGroup in logic_script's script scope. EntityGroup[0] contains handle of entity with name specified in EntityGroup[0] property etc. If multiple entities with the given named exists, handle of first found will be used.
Table MyEntityGroup is also created which contains the handles with keys being the names. (for some reason there is also MyEntityGroupArray which is 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 by Group00-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;
		}
	}
}


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