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
(Starter Examples)
m (Installation: Changed script directory to be for a generic addon instead of hlvr root)
 
(10 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{HLATools topicons}}
+
{{HLATools page|lua=1}}
  
== What is Lua? ==
+
== What is VScript? ==
 
{{HLATools topicons}}
 
{{HLATools topicons}}
Lua is a programming language frequently used in games running on the source engine. Lua scripts are able to talk to the game engine through an API layer, which allows people to create new scripts for weapons, gammemodes and much more.
+
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: Due to Half Life Alyx being a fairly new game, some of the API functionality simply does not exist yet on the engine side. For example, you may encounter some API calls that will simply return nil instead of what you were expecting.
 
  
== Create a Place For Your Scripts ==
+
== 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
  
=== This is where all your .lua files will go ===
+
== Next Steps ==
Source looks for the scripts in the scripts/vscripts folder. You can also add folders in scripts/vscripts to separate out your scripts by project or have common scripts.
+
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 ==
 
== Starter Examples ==
Line 21: 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: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