• attempt to index global 'GAMEMODE' (a nil value)
    6 replies, posted
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* [url]https://wiki.garrysmod.com/page/Hook_Library_Usage[/url]
[QUOTE=Blinkenn;51143550]You need to use hooks to use those gamemode functions *outside of a gamemode* [url]https://wiki.garrysmod.com/page/Hook_Library_Usage[/url][/QUOTE] 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.
[QUOTE=NeatNit;51143812]Just so you know, it failed to work because when autorun runs, neither GM nor GAMEMODE are defined.[/QUOTE] Oh thanks.
Sorry, you need to Log In to post a reply to this thread.