Auto Refresh

From Garry's Mod
Jump to: navigation, search


What is Auto Refresh?

Since Garry's Mod 13 all Lua scripts are reloaded "live" when they are changed on disk. This is useful if you're coding because your changes show up immediately - as soon as you save.


Autorefresh does not always work. Not knowing these restrictions can lead to confusion. These are the currently known limitations:

  • It only supports files that are automatically included by the gamemode, from autorun, effects, entities and weapons.
    • Specifically, when editing SWEP/SENT base files, SWEPs/SENTs using this base will not refresh until they are refreshed themselves.
  • It doesn't work on OSX
  • It doesn't work if the file is inside a symbolic linked directory
  • It doesn't work if Sublime Text's "Atomic Save" is enabled
  • It doesn't work with Visual Studio, VSCode works fine tough

Breaking Code

Note that when code is refreshed, the entire file is run again. This can cause issues if global data is overwritten, especially tables. To prevent this sort of thing from happening, declare dynamic global variables as themselves or a literal, as such:

-- to prevent a specific file from autorefreshing, add something like this to the top of the file:
if LangTable then return end
--Declare global dynamic variables as themselves or a literal, rather than just a literal:
LangTable = LangTable or {}

Furthermore, if your old file references hook.Add and your new file has removed that reference, the original hook will remain in place unless you use hook.Remove. The same goes for any callback function, including net.Receive, usermessage.Hook, and concommand.Add.

Disabling autorefresh

Autorefresh can lag the server when certain Lua files are edited. This happens when the refreshing cascades. This can be unwanted behavior when editing the scripts of a large project on a live server.

To disable autorefresh, add


to the command line.

Personal tools