How to generate build timestamp

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By 0none

I am working on my frist project, so excuse me if this is a dumb question :slight_smile:

For debug reasons I need to have some sort of build timestamp or incrementing number in the project, for it to be displayed in a richtextlabel ingame.

Problem is, it is hard to differenticate between exports of the project that only have small things changed. And as I am deploying the project to a console that doesn’t have a debugger, I have no way of knowing if this is an old build or not.

How would I go about doing that?

:bust_in_silhouette: Reply From: phiz

I’m a Godot newbie, but one idea could be using File.get_modified_time(), perhaps in a function that enumerates the “res://” filesystem to get a timestamp for the most recently modified file in the project. Interested to see what other ideas folks have…

:bust_in_silhouette: Reply From: jgodfrey

I’d definitely want it connected to some sort of a version control mechanism. In Git, maybe something like the branch hash.

git rev-parse <branch>

That’ll return a hash that can be used to access the exact state of the code that’s associated with the hash value.

Now, to get the value to be accessible in Godot, I’d probably create some pre-build step that would get the hash value and substitute it directly into some sort of template script that’ll ultimately be part of the build itself…

For example, maybe a template like this that can be converted into a singleton and built directly into your export…

# Version.template

extends Node

var versionHash %versionHash%

Then, in some pre-build step, I might…

  • Grab the Git hash
  • Substitute it into the above template (using whatever mechanism you want), replacing %versionHash% with the actual hash value
  • Write the resulting file out as, which would have already been defined as a singleton in the project

Now, you could access the hash information via Version.versionHash from wherever in your code…

Anyway, just an idea, but I’ve done similar things in the past with other dev environments / build systems…