Script: Difference between revisions
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		
Tip:In Team Fortress 2, backticks (
Note:Since the code is not executed from an entity's script scope and not in response to I/O, one can most likely not execute code that calls the variables 
Workaround:Define the variables as needed temporarily, e.g.  
		
	
m (Used game templates directly. Dark pre.)  | 
				 (Expand on developer console delimiters through quotation marks and backticks, moving it out of {{note}}. A new example was also created for tf2's backticks.)  | 
				||
| Line 1: | Line 1: | ||
{{lang|script}}  | {{lang|script}}  | ||
<code>'''script'''</code> is a [[console command]] in all {{src|4}} games since {{l4d2|4}} that have a {{sq}} [[Squirrel]] implementation of [[VScript]]  | <code>'''script'''</code> is a [[console command]] in all {{src|4}} games since {{l4d2|4}} that have a {{sq}} [[Squirrel]] implementation of [[VScript]], namely [[VScript#Squirrel|these]], and also in {{tf2|4}}.  | ||
== Description ==  | == Description ==  | ||
It executes Squirrel code from the root table  | It executes Squirrel code from the root table, which can contain spaces without quotation marks used. Despite this, the developer console reads the code like a typical command's value, so special console delimiters like quotation marks (<code>"</code>) and semicolons (<code>;</code>) cannot be used for scripting needs.  | ||
{{tip|In {{tf2|3}}, backticks (<code>`</code>) can be used to create `strings` safely with this command.}}  | |||
{{note|Since the code is not executed from an entity's script scope and not in response to [[I/O]], one can most likely not execute code that calls the variables <code>activator</code>, <code>caller</code> or <code>self</code>. {{workaround|Define the variables as needed temporarily, e.g. <code>script ::activator <- Entities.FindByClassname(null, "player")</code>.}} }}  | {{note|Since the code is not executed from an entity's script scope and not in response to [[I/O]], one can most likely not execute code that calls the variables <code>activator</code>, <code>caller</code> or <code>self</code>. {{workaround|Define the variables as needed temporarily, e.g. <code>script ::activator <- Entities.FindByClassname(null, "player")</code>.}} }}  | ||
| Line 17: | Line 18: | ||
}}  | }}  | ||
Should print the name of the current map in the console in most games.  | Should print the name of the current map in the console in most games.  | ||
{{pre|  | |||
script player <- Entities.FindByClassname(null, `player`);  | |||
script player.SetMaxHealth( 200 )  | |||
}}  | |||
{{tf2|only}} Using backticks and a variable, find a player then set their max health to 200.  | |||
== See also ==  | == See also ==  | ||
Revision as of 03:41, 20 January 2023
script is a console command in all 
 Source games since 
 Left 4 Dead 2 that have a 
 Squirrel implementation of VScript, namely these, and also in 
 Team Fortress 2.
Description
It executes Squirrel code from the root table, which can contain spaces without quotation marks used. Despite this, the developer console reads the code like a typical command's value, so special console delimiters like quotation marks (") and semicolons (;) cannot be used for scripting needs.
`) can be used to create `strings` safely with this command.activator, caller or self. script ::activator <- Entities.FindByClassname(null, "player").Syntax
script <code>
Example
script printl( GetMapName() )
Should print the name of the current map in the console in most games.
script player <- Entities.FindByClassname(null, `player`); script player.SetMaxHealth( 200 )
(only in 
) Using backticks and a variable, find a player then set their max health to 200.