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
(generic kio)
Line 1: Line 1:
{{Source topicon}} {{Source 2 topicon}}
{{LanguageBar}} {{Source topicon}} {{Source 2 topicon}}
{{Lang}} __NOTOC__ {{CD|CLogicScript|CPointEntity}}
{{CD|CLogicScript|CPointEntity}} __NOTOC__
[[File:Logic_script.png|left|Source 1 editor sprite]]
[[File:Logic_script.png|left|Source 1 editor sprite]]


Line 37: Line 37:
}</syntaxhighlight>
}</syntaxhighlight>
}}}}
}}}}
{{KV|Entity Scripts|intn=vscripts|scriptlist|since=L4D2|Space delimited list of [[VScript]] files (without file extension) that are executed after all entities have spawned. The scripts are all executed in the same script scope, later ones overwriting any identical variables and functions. }}
{{KV|[[Entity_Scripts#Thinker_Functions|Think function]]|intn=thinkfunction|string|since=L4D2|Name of the function within this entity's script that'll be called automatically every 100 milliseconds, or a user-defined interval if the function returns a number. Avoid [[expensive]] operations in this function, as it may cause performance problems.}}


== Inputs ==
 
{{IO|RunScriptFile|Execute a [[VScript]] file from disk, without file extension. The script contents are merged with the script scope of the receiving entity.|param=script|since={{l4d2}}|also={{tf2}}}}
{{note|For other vscript keyvalues notable for this entity like '''vscripts''', '''thinkfunction''' and inputs like '''RunScriptCode''', '''CallScriptFunction''' see [[Generic Keyvalues, Inputs and Outputs]] }}
{{IO|RunScriptCode|Execute a string of VScript source code in the scope of the entity receiving the input. String quotation may be needed when fired via console. {{bug|In Hammer, using string arguments will corrupt the [[VMF]] file's structure, making the file unviewable for the next Hammer session.{{fix|Remove the string argument manually with a text editor.}}}}{{note|{{tf2}} Backtick characters ` are replaced with quotation marks at runtime, allowing quotation marks to be used when normally not possible.}}|param=string|since={{l4d2}}|also={{tf2}}}}
{{IO|CallScriptFunction|Calls a VScript function defined in the scope of the receiving entity.|param=string|since={{l4d2}}|also={{tf2}}|nofgd=1}}
{{IO|TerminateScriptScope|Destroys the script scope of the receving entity.|only={{tf2}}|nofgd=1}}


== See also ==
== See also ==

Revision as of 23:05, 11 October 2024

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 Team Fortress 2 and Mapbase Mapbase and it is the container for VScripts. In Left 4 Dead 2, for example, this entity 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