attempt to index global 'GAMEMODE' (a nil value)

Ive been trying to get my addon to print 3 lines but keeps giving me:

[ERROR] addons/apbrjokerbox/lua/autorun/server/init.lua:1: attempt to index global ‘GAMEMODE’ (a nil value)

  1. unknown - addons/apbrjokerbox/lua/autorun/server/init.lua:1

Ive tried GM:, GM. GAMEMODE:, and GAMEMODE. they all gave me the same error for lines:

function GAMEMODE.Initialize()
print(“Initialize”)
end

function GAMEMODE.InitPostEntity()
print(“InitPostEntity”)
end

hook.Add( “InitPostEntity”, “some_unique_name”, function()
print( “Initialization Hook” )
end )

Can anyone help?

That’s not quite how functions work. I have no time now, but if for some reason, by tomorrow, nobody has explained it, I’ll do it.

-snip- Stupid

You need to use hooks to use those gamemode functions
outside of a gamemode

https://wiki.garrysmod.com/page/Hook_Library_Usage

Im beginning lua can you dumb that down a bit please? xD

EDIT: I may or may not have just figured it out. I removed everything but the hook and it printed.

Just so you know, it failed to work because when autorun runs, neither GM nor GAMEMODE are defined.

Oh thanks.