Return to Main Page

HL2GMED Instances

Page white text.png Description:This is an introduction to the lua language in general and is a recommended read if you are a beginner.
link=User:Dim1xs Author:Dim1xs
Calendar.png Created: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.

In Practice

So, to load a script on the server instance, I would do:

lua_dofile myscript.lua
               
Now 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 myscript
               
Now 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. NewerShared.png Shared - This is used on both the server and the client.

print( "Loaded from SHARED." )
               

2. NewerServer.png 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. NewerClient.png Client - This side, is used only on your local game, it can`t do server-side scripts.

if CLIENT then
   print( "Loaded from CLIENT." )
end
               
Thank you for reading this article, see ya later!

JOIN HL2GMED DISCORD SERVER!