Vscript Fundamentals

From Valve Developer Community
Revision as of 01:33, 20 August 2014 by Rectus (talk | contribs) (Created page with "This article aims to describe fundamental concepts and uses of VScript scripting. {{todo}} == Tables and Script Scopes == {{todo}} == Script Handles == {{todo}} == Ent...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This article aims to describe fundamental concepts and uses of VScript scripting.

To do

Tables and Script Scopes

To do

Script Handles

To do

Entity Scripts

Adding a script to the vscripts (Entity Scripts) KeyValue of a server-side entity loads the script as an Entity Script. The script is executed when the entity spawns, and loads into a unique script scope made up of an unique identifier followed by the entity name or class name; _<unique ID>_<entity name>.

A think function can be set with the thinkfunction KeyValue, the specified script function every 0.1 seconds. While it has the potential to become expensive, a programmer is able to limit the amount of code executed. Functions can also be manually called through the I/O system with the input RunScriptCode function_name(argument, ...).

Entity Scripts have a self reference to their owning script handle, allowing the script easy access to control the entity through its class methods.

To do:  activator and caller are also available, but always seem to reference the same thing as self.

The script can be reloaded with console command ent_fire <name of entity> runscriptfile <relative vscript path>. This is useful for quick script reloading.

I/O system interaction

If available in the game API, scripts can use the EntFire() and DoEntFire() functions to fire outputs to map entities.

If arguments for activator and caller are available in the functions, they take a script handle and can be used to fire an output to an entity using the "!self" or "!activator" keyword, even without having to know its name, as long as the handle is available.

Arbitrary VScript code can be run from the I/O system, using the RunScriptCode input available in all entities. The code will run in the calling entities script scope.

Warning.png Warning: Never use double-quotation marks in any Hammer Output, since it will corrupt the map file. This means that strings cannot be passed with RunScriptCode.


Entity handle
Also known as EHANDLE. To do: Looks like some sort of pointer reference to an entity.
Script handle
An entity instance with accessors and mutators to the C++ entity object. Also known as HScript.
Script scope
The table where the variables, functions and classes of a VScript are placed.

See Also


Left 4 Dead 2 Scripting

Dota 2 Scripting