Script

From Valve Developer Community
Revision as of 04:41, 20 January 2023 by Orinuse (talk | contribs) (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.)
Jump to navigation Jump to search
English (en)中文 (zh)Translate (Translate)

script is a console command in all Source Source games since Left 4 Dead 2 Left 4 Dead 2 that have a Squirrel Squirrel implementation of VScript, namely these, and also in Team Fortress 2 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.

Tip.pngTip:In Team Fortress 2, backticks (`) can be used to create `strings` safely with this command.
Note.pngNote: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 activator, caller or self.
PlacementTip.pngWorkaround:Define the variables as needed temporarily, e.g. 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 Team Fortress 2) Using backticks and a variable, find a player then set their max health to 200.

See also