Gamemode Init Startup Issue

I am working on a gamemode and everything runs perfectly and fine with no errors.

But this is only after re-saving the init.lua file on the server while someone is playing. Otherwise the gamemode does not run the functions like GM:PlayerSpawn() nor create any of the timers in it.

What could be the issue? Everything runs fine after re-saving it… It also seems that timers and such stop and the gamemode once again stays static if there are no players…

Your load-order is wrong. When you auto-refresh, everything is kept in memory but a new GM is created and overwrites the old, timers are reissued and hooks too.

If you ran this ( the do/end gives the same style of scope as two files would have ):

[lua]do
print( MY_VAR );
end

do
MY_VAR = true;
end[/lua]

You’d print( nil ) or blank line. Upon auto-refresh, it’d print true. Your load order is incorrect. Make sure you’re loading things properly. Here’s an example: https://dl.dropboxusercontent.com/u/26074909/tutoring/loading_files_across_realms.lua.html

And in action: https://dl.dropboxusercontent.com/u/26074909/tutoring/_redistributable/basedev_gamemode.rar

or

https://dl.dropboxusercontent.com/u/26074909/tutoring/_redistributable/basedev_gamemode/gamemode/cl_init.lua
https://dl.dropboxusercontent.com/u/26074909/tutoring/_redistributable/basedev_gamemode/gamemode/init.lua
https://dl.dropboxusercontent.com/u/26074909/tutoring/_redistributable/basedev_gamemode/gamemode/sh_init.lua

All includes can be in a shared file and still work as intended. Load shared files first; shared should be your enumerations, declarations, etc… Server or client next doesn’t matter; then load content. You should be able to set up a load-order which ensures everything is declared before it is used, because if it is used before it is declared then you’ll have the issue you’re describing.

So basically, the issue is that I may be including files that are not shared before I am including the shared files?

It’s just very odd because I have never had this issue before and whenever I make a new gamemode, I just use the same base startup I always have…

[editline]29th May 2014[/editline]

I just really don’t comprehend your explanation. Rate me dumb if you like but I checked out all of the links and none of it really makes sense as to why it may not be working. I included the shared files first and all of the timer declarations are at the bottom of the init.lua …Should these be in the shared.lua?

This will work



function Test() 
    print("Test")
end

Test()


This won’t



Test()

function Test()
    print("Test")
end


That is what Acecool is saying, when the gamemode first loads, it reads the lua file top to bottom, then when you autorefesh, it has already cached the functions so it works.

I understand that much but I assure you I have looked my init from top to bottom and nothing is called before it is declared…

[editline]30th May 2014[/editline]

Atleast, not that I have seen from the many times I have read over the entire thing.

[editline]30th May 2014[/editline]

Possibly someone with a keener eye then myself might be able to find the issue area:

-snipped- FIXED
I’d prefer noone steal anything though, thanks.