SteamVR/Environments/Scripting/Map Scripts

From Valve Developer Community
Jump to: navigation, search

The SteamVR Workshop Tools support map specific scripts that are executed when the map loads. These scripts can contain specially named callback functions that get executed by the script system.

Map scripts are designated by naming the script the same as the map, and placing it into the \steamvr_environments\game\steamtours_addons\<addon_name>\scripts\vscripts\map_scripts\ directory.


Callbacks

Adding a function with the specific signature to the map script lets it get called from the game code.

Function Signature Description
OnInit void OnInit() Called when the script system loads.
OnPostInit void OnPostInit() Called after the script system has been initialized.
OnPrecache void OnPrecache(handle context) Called when assets are precached.
OnActivate void OnActivate()
OnInit void OnInit() Called when the script system loads.
OnGameplayStart void OnGameplayStart()
OnPlayerSpawned void OnPlayerSpawned() Called after the hosting player has spawned.
OnHMDAvatarAndHandsSpawned void OnHMDAvatarAndHandsSpawned() Called when the VR equipment of the hosting player is accessible.
OnDeactivate void OnDeactivate()
OnPreShutdown void OnPreShutdown()
OnShutdown void OnShutdown()


Script System Functions

Functions available to the map script from the script system.

Function Signature Description
ScriptSystem_AddPerFrameUpdateFunction void ScriptSystem_AddPerFrameUpdateFunction(function updateFunction) Adds a function in the map script to be called every frame (90 FPS, 0.011 seconds).
ScriptSystem_RemovePerFrameUpdateFunction void ScriptSystem_RemovePerFrameUpdateFunction(function updateFunction) Removes a previously added update function.
AddConVar void AddConVar(string conVarName, variable defaultValue, string type, table scope, string helpText, function callback) Adds a new console variable bound to the specified script function.
SetConVar void SetConVar(string conVarName, variable value) Sets a scripted convar value.
GetConVar string GetConVar(string conVarName, int prevIndex = nil) Returns the name? of the specified convar.