Skip to content

The Environment

Autorun-ng scripts run in special environments. That’s where Autorun comes from.

It still runs inside of the same clientside global environment that Garry’s Mod addons use. But the key difference is that Autorun adds a separate fenv in between.

The only way to access globals from the global environment is through the value _G. You must explicitly index, as like _G.print, instead of accessing it as print.

This is due to security reasons. Garry’s Mod addons have full access to the global environment, they could always replace a function with another which will detect when you call it. You should limit the amount of accesses you make to the global environment _G as much as possible.

Autorun-ng by default provides all of the built-in lua standard libraries like string, table, etc, which are saved upon init right before any code loads into the Autorun environment. This means that if an addon replaces, say, string.format, that won’t affect code running in Autorun-ng which is using the saved string.format.

Autorun.print("I'm running on server " .. GetHostName())

To fix this, you must access it through _G:

Autorun.print("I'm running on server " .. _G.GetHostName())

See the Lua API reference for more information on what is available in the Autorun environment.