Detect when a file is changed

Anyway to detect when a file is changed? Like so if I am making edits on my server is there a way I can detect if a change was made and display a message saying “BLAH file was changed, please comment on any bugs you experience with it”.

not much else to say :v:

For specific files, you could do one of many different things.

OnReloaded hook as mentioned tells you that at least one file was changed. If its run on both client and server, its a shared file. If its run on the client, its a client file ( and a new file will appear in their lua/cache folder. If it is a server file, then it’ll run on the server.

You could crc all files, and when OnReloaded is called, re-crc all files to see which one changed - you could even do it based on size. It may be expensive to do it, but having OnReloaded return the file which was changed is a requested feature, so hopefully they’ll add it at some point.

At the expense of making _G bigger…



if SOME_SPECIAL_VARIABLE_NAME_THIS_IS_COOL then
   -- I was reloaded
end
SOME_SPECIAL_VARIABLE_NAME_THIS_IS_COOL = true

At the top of any file does the trick wonderfully.

That doesn’t solve the issue of it reloading the entire game-mode, or at least the entire realm which was modified.

But, to add to what you say; that is almost how you make auto-refresh compatible game-modes.

Hooks get wiped on refresh, timers, and GM functions too ( merged over top I believe, as custom GM data stays put but a lot of other GM stuff does not, I believe it loads the base and then it loads your game-mode )…

If you want to define something auto-refresh compatible, while retaining data:

[lua]//
// Create a new instance and make it auto-refresh compatible.
//
if ( !notify ) then
notify = { };
notify.__index = notify;
notify.__type = “Notification”;
notify.__messages = { };
notify.__count = 0;
end[/lua]

Since notify is a global var for my notify class ( rewritten logic from default which prevents the Think hook from running when it isn’t needed; it adds when a message is added and removes when the last message is removed; on top of that the count is managed so it doesn’t need to run table.Count every time )

If you want to see that: https://dl.dropboxusercontent.com/u/26074909/tutoring/classes/class_notify.lua.html

Although typical vars are loaded like so using if it is set, use it, or initialize it:
[lua]MY_VAR = MY_VAR || { }[/lua]

One good way, is how I do my language class - I call this inside the function so its self contained; although it could be done in the if !language ) portion like notify, it is done like this because many dictionaries can be used.
[lua]function language:InitDictionary( _lang )
if ( !self.__dictionary ) then self.__dictionary = { }; end
if ( !self.__dictionary[ _lang or self.__default ] ) then self.__dictionary[ _lang or self.__default ] = { }; end
end[/lua]

Slightly off on a tangent, but hopefully it contains some helpful information.

You can deny autorefresh to files using your way Ozy.

[lua]if ( SOMETHING ) then return; end
SOMETHING = true; – prevent autorefresh for this file as its not needed to be reloaded[/lua]