Logic script: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
(-removed toc and kept only the most relevant inputs and keyvalues for this entity)
Line 1: Line 1:
{{toc-right}}
__NOTOC__
{{lang|Logic_script}}
{{lang|Logic_script}}
{{CD|CLogicScript|CPointEntity}}
{{CD|CLogicScript|CPointEntity}}
Line 6: Line 6:
==KeyValues==
==KeyValues==
{{KV|EntityGroup[0]|to=EntityGroup[15]|intn=Group00|intn2=Group15|target_destination|Entities to add in the EntityGroup array for the script.}}
{{KV|EntityGroup[0]|to=EntityGroup[15]|intn=Group00|intn2=Group15|target_destination|Entities to add in the EntityGroup array for the script.}}
{{KV BaseEntity}}
{{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.}}
{{note|logic_script in L4D2 is missing KeyValues for Entity Scripts and Script think function. These additional keys can to be added to the entity with SmartEdit turned off as '''vscripts <code><[[string]]></code>''' and '''thinkfunction <code><[[string]]></code>''', respectively.}}
{{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 ==
== Inputs ==
{{I BaseEntity}}
{{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}}}}
 
{{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. {{ModernBugfix|In Hammer, using string arguments will corrupt the [[VMF]] file's structure, making the file unviewable for the next Hammer session.|Remove the string argument manually with a text editor.}}{{ModernNote|{{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}}}}
== Outputs ==
{{IO|CallScriptFunction|Calls a VScript function defined in the scope of the receiving entity.|param=string|since={{l4d2}}|also={{tf2}}|nofgd=1}}
{{O BaseEntity}}
{{IO|TerminateScriptScope|Destroys the script scope of the receving entity.|only={{tf2}}|nofgd=1}}


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

Revision as of 11:08, 22 March 2023

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

Template:Entity It is also available in Team Fortress 2 Team Fortress 2 and it 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

EntityGroup[0] (Group00) to EntityGroup[15] (Group15) <targetname>
Entities to add in the EntityGroup array for the script.
Entity Scripts (vscripts) <scriptlist> (in all games since Left 4 Dead 2)
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.
Think function (thinkfunction) <string> (in all games since Left 4 Dead 2)
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

RunScriptFile <scriptRedirectInput/string> (in all games since Left 4 Dead 2) (also in Team Fortress 2)
Execute a VScript file from disk, without file extension. The script contents are merged with the script scope of the receiving entity.
RunScriptCode <stringRedirectInput/string> (in all games since Left 4 Dead 2) (also in Team Fortress 2)
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. Template:ModernBugfixTemplate:ModernNote
CallScriptFunction <stringRedirectInput/string> (in all games since Left 4 Dead 2) (also in Team Fortress 2) !FGD
Calls a VScript function defined in the scope of the receiving entity.
TerminateScriptScope  (only in Team Fortress 2) !FGD
Destroys the script scope of the receving entity.

See also

External links