• gamemode returns nill unless a lua-refresh happens
    4 replies, posted
Hello there! I have this small clientside file, that outputs an error on joining and thus halts it's loading. Upon refreshing a file the code suddenly works. It's in autorun and is ACSL'd. Code: [CODE] local test = gmod.GetGamemode() or GAMEMODE print("[IWL] "..iwl.str.gl[IWL_CL_STATE]) [...] function test:RenderScreenspaceEffects() <<nastystufftohappen>> end[/CODE] Console error: [CODE] [IWL] Trying to load! [ERROR] lua/autorun/client/iwl_module_bld.lua:65: attempt to index local 'test' (a nil value) 1. unknown - lua/autorun/client/iwl_module_bld.lua:65[/CODE] Anyone has any idea? I'm pretty sure I'm missing something trivial about both gmod.GetGamemode() and GAMEMODE returning nil on the first launch, but apparently I couldn't find it after a couple of hours of searching.
You're overwriting the test argument with the line [QUOTE]local test[/QUOTE] Simply remove it to fix your error.
That would render the code not to work at all, obviously. It wouldn't even fix the error, as it'd still be a nil. In case you mean it's a global variable used by the core, well, neither renaming it [CODE] [ERROR] lua/autorun/client/iwl_module_bld.lua:65: attempt to index local 'randomgamemode' (a nil value) 1. unknown - lua/autorun/client/iwl_module_bld.lua:65 [/CODE] nor replacing it with the good old GM seems to work [CODE] [ERROR] lua/autorun/client/iwl_module_bld.lua:65: attempt to index local 'GM' (a nil value) 1. unknown - lua/autorun/client/iwl_module_bld.lua:65 [/CODE]
I'm not 100% on that, but files in Autorun might be executed before the game mode has loaded. Try [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PostGamemodeLoaded]GM:PostGamemodeLoaded[/url] [editline]17th May 2017[/editline] Why are you accessing the game mode table in the first place?(instead of using the hook module)
That fixed it, thank you! (I need to grab some monitoring data for a dll module, couldn't find a better way)
Sorry, you need to Log In to post a reply to this thread.