Garry's Mod Wiki

Revision Difference

States#525315

<cat>Dev.GettingStarted</cat> <title>Realms / States</title> The states or so called realms represent different Lua states. There are 3 Lua states in Garry's Mod. # Client <upload src="19952/8d7b58bc25e14dd.png" size="342" name="image.png" /> The **Client** state is basically your game client. It handles things such as visual rendering. It can communicate with Server state via the <page>net</page> as an example. A variable set on **Client** state cannot be retrieved on Server state without networking it. The **Client** state is basically your game client. It handles things such as visual rendering. It can communicate with Server state via the <page>net</page> library, as an example. A variable set on the **Client** state cannot be retrieved on the Server state without networking it. A common issue is to give the client too much freedom, the client should only respond to what the server tells it, and not the other way around. # Server <upload src="19952/8d7b58d7428c9c6.png" size="337" name="image.png" /> The **Server** state handles things on the server; it's the only state used on Dedicated Servers. This handles things like telling entities what to do, controlling weapons/players and all game logic (what happens when and how in gamemodes). It can communicate with Client state via the <page>net</page> as an example. A variable set on **Server** state cannot be retrieved on **Client** state without networking it. The **Server** state handles things on the server; it's the only state used on Dedicated Servers. This handles things like telling entities what to do, controlling weapons/players and all game logic (how and when stuff happens in gamemodes). It can communicate with Client state via the <page>net</page> library, as an example. A variable set on the **Server** state cannot be retrieved on the **Client** state without networking it. # Menu <upload src="19952/8d7b58bce4f33d1.png" size="343" name="image.png" /> The **Menu** state is a hidden and isolated state for the Main Menu. It has some vital functions available to make Main Menu functional and cannot communicate with **Client** or **Server** states. Any Lua ran in this state will run regardless of `sv_allowcslua`. # Other These are not an actual states, rather, they signify that the function or hook can be executed in each one of the specified states. These are not actual states; rather, they signify that the function or hook can be executed in each one of the specified states. In the wiki you may also see the following pseudo-states: - Shared (Client and Server) <upload src="19952/8d7b58d999caa0e.png" size="487" name="image.png" /> - Client and Menu <upload src="19952/8d7b58a905836e9.png" size="506" name="image.png" /> - Shared and Menu (all states - Client, Server and Menu) <upload src="19952/8d7b58e58180414.png" size="552" name="image.png" /> It doesn't necessarily mean the function/hook will return the same values in the different states, or that it does the same thing. For example, the function <page>Entity:GetPos</page> can be called on Server and Client, so it is shared. <page>undo.GetTable</page> is also a shared function, but it works differently on client and server as explained in its description. The <page>math</page> and <page>string</page> on the other hand can be used in all 3 states. It doesn't necessarily mean the function/hook will return the same values in the different states, or that it does the same thing. For example, the function <page>Entity:GetPos</page> can be called on Server and Client, so it is shared. <page>undo.GetTable</page> is also a shared function, but it works differently on Client and Server as explained in its description. The <page>math</page> and <page>string</page> libraries, on the other hand, can be used in all 3 states.