Debug Common
scripts/vscripts/alyxlib/debug/common.lua
Properties
version
Default value
"v2.2.0"
Methods
FindEntityByPattern
Finds the first entity whose name, class or model matches pattern.
pattern can also be an entity handle string, e.g. 0x0026caf8
Parameters
pattern
string
The search pattern to look for.exact
boolean?
If true the pattern must match exactly, otherwise wildcards will be used.
Returns
- EntityHandle?
The found entity, or nil if not found.
FindAllEntitiesByPattern
Finds all entities whose name, class or model match pattern.
pattern can also be an entity handle string, e.g. 0x0026caf8
Parameters
pattern
string
The search pattern to look for.exact
boolean?
If true the pattern must match exactly, otherwise wildcards will be used.
Returns
- EntityHandle[]
PrintEntityList
Prints a formated indexed list of entities with custom property information. Also links children with their parents by displaying the index alongside the parent for easy look-up.
If no properties are supplied the default properties are used: GetClassname, GetName, GetModelName If an empty property table is supplied only the base values are shown: Index, Handle, Parent Property patterns do not need to be functions.
Parameters
list
EntityHandle[]
List of entities to print.properties(optional)
string[]
List of property patterns to search for.
PrintAllEntities
Prints information about all existing entities.
Parameters
properties(optional)
string[]
List of property patterns to search for when displaying entity information.
PrintDiffEntities
Prints information about any new entities since the last time Debug.PrintAllEntities was called.
Parameters
properties(optional)
string[]
List of property patterns to search for when displaying entity information.
PrintEntities
Print entities matching a search string.
Searches name, classname and model name.
Parameters
search
string
Search string, may include*.exact
boolean
If the search should match exactly or part of the name.dont_include_parents
boolean
Parents won't be included in the results.properties(optional)
string[]
List of property patterns to search for when displaying entity information.
PrintAllEntitiesInSphere
Prints information about all entities within a sphere.
Parameters
origin
Vector
Position to search for entities at.radius
number
Max radius to find entities within.properties(optional)
string[]
List of property patterns to search for when displaying entity information.
PrintTable
Prints the keys/values of a table and any tested tables.
This is different from DeepPrintTable in that it will not print members of entity handles.
Parameters
tbl
table
Table to printprefix(optional)
string
Optional prefix for each lineignore(optional)
any[]
Optional nested tables to ignoremeta(optional)
boolean
If meta tables should be printedcustomIterator(optional)
function
Optional custom iterator to use (default=pairs)
PrintTableShallow
Prints the keys/values of a table but not any tested tables.
Parameters
tbl
table
Table to print.
PrintList
Prints an ordered table as a numbered list in the console.
Parameters
tbl
table
Table to print.prefix(optional)
string
Optional prefix for each line.
PrintSimpleTable
Prints all the values in a table, one value per line, without any numbering or padding.
Parameters
tbl
table
Table to print.
PrintValue
Prints a value and its type in an easy to read format.
Parameters
value
any
ShowEntity
Draws a debug line to an entity in game.
Parameters
ent
EntityHandle,string
Handle or targetname of the entity(s) to find.duration
number?
Number of seconds the debug should display for.
Returns
- EntityHandle[]|EntityHandle?
Entities found, or the entity given
PrintEntityCriteria
Prints all current context criteria for an entity.
Parameters
ent
EntityHandle
PrintEntityBaseCriteria
Prints current context criteria for an entity except for values saved using storage.lua.
Parameters
ent
EntityHandle
GetClassname
Gets the class name of a vscript entity based on its metatable, e.g. CBaseEntity.
If the entity is an EntityClass entity the original Valve class name will be returned instead of the EntityClass.
Parameters
ent
EntityHandle
The entity to get the class name of.
Returns
- string
The class name of the entity or "none" if not found.
PrintMetaClasses
PrintGraph
Prints a visual ASCII graph showing the distribution of values between a min/max bound.
E.g.
Example
Example
Parameters
height
integer
Height of the actual graph in print rows. Heigher values give more accurate results but can overflow the console making it hard to read.min_val(optional)
number
Minimum expected value forname_value_pairs. Default is0.max_val(optional)
number
Maxmimum expected value forname_value_pairs. Default is1.name_value_pairs
table<string,number>
Values to visualize on the graph.
PrintInheritance
Prints a nested list of entity inheritance.
Parameters
ent
EntityHandle
SimpleVector
Returns a simplified vector string with decimal places truncated.
Parameters
vector
Vector,QAngle,table
Returns
- string
Sphere
Draw a simple sphere without worrying about all the properties.
Parameters
x
number
X positiony
number
Y positionz
number
Z positionradius(optional)
number
Radius of the spheretime(optional)
number
Lifetime in seconds, default 10color(optional)
Vector
Color vector [Red, Green, Blue]
Line
Draw a simple line without worrying about all the properties.
Parameters
startPos
Vector
Start positionendPos
Vector
End positiontime(optional)
number
Lifetime in seconds, default 10color(optional)
Vector
Color vector [Red, Green, Blue]
EntStr
Returns a string made up of an entity's class and name in the format "[class, name]" for debugging purposes.
Parameters
ent
EntityHandle
Returns
- string
DumpConvars
Dumps a list of convars and their values to the console.
Parameters
convars
string[]
List of convar names to dump
FindEntityByHandleString
Finds an entity by its handle as a string.
Certain parts of the string can be omitted and the following are all valid:
Example
Please note that omitting the colon is not allowed in a single string, i.e. "table 0x0012b03" will not work.
Parameters
tblpart
string
Entity table stringcolon(optional)
string
The colon parthash(optional)
string
The hash part
Returns
- EntityHandle?
IsEntityHandleString
Gets whether the string is in the format of an entity handle.
Parameters
handleString
string
The handle string
Returns
- string?
The hash part or nil if not an entity handle
ToOrdinalString
Converts a number to its ordinal string representation (e.g., 1 → "1st", 2 → "2nd", 3 → "3rd").
Parameters
n
integer
Number to convert to ordinal representation
Returns
- string
GetSourceLine
Get the script name and line number of a function or traceback level.
Parameters
f
integer,function
Level or function
Returns
- string
Try
Safely calls a function while handling any errors.
If an error occurs, a warning will be printed to the console.
Parameters
action
function
The function to call
TableStr
Converts a table to single line string representation.
Parameters
tbl
table
The table to convert.
Returns
- string
The string representation.
Functions
entspawn
Spawns an entity synchronously.
Parameters
classname
string
The classname of the entityspawnkeys(optional)
table,string
The spawnkeys table or targetname
Returns
- EntityHandle