This article relates to the game "Half-Life: Alyx". Click here for more information.
This article relates to the workshop tools for "Half-Life: Alyx". Click here for more information.
This article's documentation is for Source 2. Click here for more information.

Difference between revisions of "Half-Life: Alyx Workshop Tools/Lua Scripting/Getting Started"

From Valve Developer Community
Jump to: navigation, search
(Added installation steps for the bootstrap vscripts and renamed some sections)
m (Installation: Changed script directory to be for a generic addon instead of hlvr root)
 
(8 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{HLATools topicons}}
+
{{HLATools page|lua=1}}
  
 
== What is VScript? ==
 
== What is VScript? ==
 
{{HLATools topicons}}
 
{{HLATools topicons}}
Scripting in Half-Life: Alyx is done using Lua, an easily embeddable scripting language developed by PUC Rio. Source 2 and some branches of Source 1 implement an abstraction layer known as "vscript", which allows Valve to enable scripting for games in a variety of languages including: Lua, Squirrel, GameMonkey and Python. The vscript API for Half-Life: Alyx is much more limited than that of SteamVR Home, but in the future Valve may add new functions and API features. For now, it's not possible to add new weapons or tools, but hopefully that will change in the future.
+
Scripting in Half-Life: Alyx is done using Lua, an easily embeddable scripting language developed by PUC Rio. Source 2 and some branches of Source 1 implement an abstraction layer known as "vscript", which allows Valve to enable scripting for games in a variety of languages including: Lua, Squirrel, GameMonkey and Python. The vscript API for Half-Life: Alyx is much more limited than that of SteamVR Home, but in the future Valve may add new functions and API features. For now, it can be rather cumbersome to add new weapons or tools.
* NOTE: Valve does not ship any scripts with Half-Life: Alyx, meaning you will need to manually install the Source 2 runtime scripts which will initialize the entity subsystem, among other things. Without these scripts, many of the API functions will return nil.  
 
  
 
== Installation ==
 
== Installation ==
1. Find your hlvr folder  
+
1. Find your hlvr addon folder  
*  The path should looks something like: D:\SteamLibrary\steamapps\common\Half-Life Alyx\game\hlvr, depending on where you installed it.
+
*  The path should looks something like: C:\Program Files (x86)\Steam\steamapps\common\Half-Life Alyx\game\hlvr_addons\<your_custom_addon_name>, depending on where you installed it.
 
2. Create folders
 
2. Create folders
 
* Create a folder called: scripts. Inside that folder create another folder called: vscripts.  
 
* Create a folder called: scripts. Inside that folder create another folder called: vscripts.  
* you should now be in a directory that looks like this: D:\SteamLibrary\steamapps\common\Half-Life Alyx\game\hlvr\scripts\vscripts
+
* you should now be in a directory that looks similar to this: C:\Program Files (x86)\Steam\steamapps\common\Half-Life Alyx\game\hlvr_addons\<your_custom_addon_name>\scripts\vscripts
3. Install the required scripts
 
* You can obtain the required runtime scripts [https://github.com/JJL772/half-life-alyx-scripts here] or from your SteamVR Home installation directory.
 
* Clone or download the repo and move the vscripts folder to hlvr/scripts
 
* If using SteamVR Home, copy the scripts/vscripts folder from SteamVR home to hlvr/scripts
 
  
 
== Next Steps ==
 
== Next Steps ==
Line 27: Line 22:
 
1. Hello Gordon: '''[[Half-Life:_Alyx_Workshop_Tools/Level_Design/Lua_Scripting_Examples/Hello_Gordon| The classic example]]'''.
 
1. Hello Gordon: '''[[Half-Life:_Alyx_Workshop_Tools/Level_Design/Lua_Scripting_Examples/Hello_Gordon| The classic example]]'''.
  
== Example Index ==
+
== See More Examples Here ==
'''[[Half-Life:_Alyx_Workshop_Tools/Level_Design/Lua_Scripting_Examples|Half-Life: Alyx Lua Scripting Examples]]'''
+
[[:Category:Half-Life:_Alyx_Workshop_Tools/Level_Design/Lua_Scripting | Lua Scripting ]]
  
 
[[Category:Source 2]]
 
[[Category:Source 2]]
 
[[Category:Scripting]]
 
[[Category:Scripting]]
[[Category:Half-Life:_Alyx_Workshop_Tools]]
 
[[Category:Half-Life:_Alyx_Workshop_Tools/Level_Design/Lua_Scripting]]
 

Latest revision as of 14:52, 1 June 2020

What is VScript?

Scripting in Half-Life: Alyx is done using Lua, an easily embeddable scripting language developed by PUC Rio. Source 2 and some branches of Source 1 implement an abstraction layer known as "vscript", which allows Valve to enable scripting for games in a variety of languages including: Lua, Squirrel, GameMonkey and Python. The vscript API for Half-Life: Alyx is much more limited than that of SteamVR Home, but in the future Valve may add new functions and API features. For now, it can be rather cumbersome to add new weapons or tools.

Installation

1. Find your hlvr addon folder

  • The path should looks something like: C:\Program Files (x86)\Steam\steamapps\common\Half-Life Alyx\game\hlvr_addons\<your_custom_addon_name>, depending on where you installed it.

2. Create folders

  • Create a folder called: scripts. Inside that folder create another folder called: vscripts.
  • you should now be in a directory that looks similar to this: C:\Program Files (x86)\Steam\steamapps\common\Half-Life Alyx\game\hlvr_addons\<your_custom_addon_name>\scripts\vscripts

Next Steps

At this point, you can begin writing scripts.

In order to load them, you'll need to move the scripts into the vscripts directory. Now they can be loaded using the script_reload_code and cl_script_reload_code console commands, which take a path to your script relative to the vscripts directory.

Starter Examples

These basic examples will show you how to connect the game world to the scripts that you write:

1. Hello Gordon: The classic example.

See More Examples Here

Lua Scripting