I am trying to create a timer that would not be interrupted by map changes and server restarts. Almost like a global timer. I’ve got one working using text files, but I am curious if there is a more efficient way of doing this. New ideas would be great.
Nope. Data stored in memory (such as a variable containing an os.time() value ) is lost when the lua environment is shut down. The most common way to account for this is to store simple things (like a single integer) in text files, or more complicated things(like player inventories) in database files.
textfile and database is the most common way of storing stuff in garrysmod. Databases are not created for storing one variable like you want, they’re created for storing variables on every player, for example.
A textfile is probably the best way here.
You have pretty much the best way of doing it. You could do a convar that archives itself with FCVAR_ARCHIVE. Anything besides that is overkill.
Not going to be able to store a timer over map changes and etc saint
Going to need to store it, and there is different ways to store it like jet and etc said.
A database can be document-based.
Even if you save the time to any sort of database, the timer will still be interrupted when the map restarts, saving to a database will only allow it to start again once the map is loaded.
You could save the timestamp at each save, then just take the timestamp difference or something and it’d still add up even if the server has been offline after a week.
Yeah my current timer takes single integers from os.date and creates a string. I write it to the file and anything calling that txt file uses a global function to get the proper timestamp. Thanks for the confirmation.