HL2GMED Instances
![]() | This is an introduction to the lua language in general and is a recommended read if you are a beginner. |
![]() | Dim1xs |
![]() | September 28th 2023 |
Introdution
As a bit of a recap, I'll remind you there can be up to three instances at once - the Server Instance, the Client Instance, and the Menu Instance (broken rn). When loading a script, a Lua Instance turns the plain text inside of it into code. This process is called compiling, and is done every time a script is loaded. Right after the code is compiled, it runs on the instance it was compiled on. Scripts can be loaded as much as you like. You can load a script, modify it outside of the game, and load it up again as much as you want.
If I wanted to load a script on the client instance, I would do:
But it is important for you to note that when you change the script from the '../lua/autorun' directory, you definitely need to restart the map in order for the changes to apply. And if your script is located in the directory '../lua', you just need to restart it using the commands listed above.
JOIN HL2GMED DISCORD SERVER!
In Practice
So, to load a script on the server instance, I would do:lua_dofile myscript.luaNow this script is run on the server instance.
If I wanted to load a script on the client instance, I would do:
lua_dofile_cl myscriptNow this script is run on the client instance.
But it is important for you to note that when you change the script from the '../lua/autorun' directory, you definitely need to restart the map in order for the changes to apply. And if your script is located in the directory '../lua', you just need to restart it using the commands listed above.
Instance Occurrences
1.
Shared - This is used on both the server and the client.
print( "Loaded from SHARED." )
2.
Server - This side, is used on Dedicated Servers, and your local hosted game, it can`t do client-side scripts.
if SERVER then print( "Loaded from SERVER." ) end
3.
Client - This side, is used only on your local game, it can`t do server-side scripts.
if CLIENT then print( "Loaded from CLIENT." ) endThank you for reading this article, see ya later!
JOIN HL2GMED DISCORD SERVER!