Unique identifier for a game
Moderator: OpenTTD Developers
Unique identifier for a game
Is there something I can use that will uniquely identify a game? I am thinking of something like a GUID for each game instance?
Re: Unique identifier for a game
Reading through the squirrel docs there are methods such as time() and getenv() that I could use to generate a /reasonably/ unique id, however I cant work out how to get access to the system functions.
- planetmaker
- OpenTTD Developer
- Posts: 9432
- Joined: 07 Nov 2007 22:44
- Location: Sol d
Re: Unique identifier for a game
Do you mean savegame or map? Then the answer is 'no'. But a GameScript must provide a unique identifier (GSInfo::GetShortName()), something like a name with exactly four letters.aidos wrote:Is there something I can use that will uniquely identify a game? I am thinking of something like a GUID for each game instance?
Other than that... I don't quite get what kind of unique identifier you could mean or as to what you aim for. Maybe you can describe a bit more what you try to achieve?
You might try to check for certain map-specific settings, like the random seed, the map size, the climate and maybe some other variables. Checkout class GSGameSettings:
http://nogo.openttd.org/api/trunk/class ... tings.html
Cheers,
pm
OpenTTD: manual | online content | translations | Wanted contributions and patches
#openttdcoop: blog | wiki | public server | DevZone | NewGRF web translator
DevZone - home of the free NewGRFs: OpenSFX | OpenMSX | OpenGFX | Swedish Rails | OpenGFX+ Trains|RV|Industries|Airports|Landscape | NML
Re: Unique identifier for a game
If you have a generated map (no heightmap, and no scenario started from flat map), you can query the map generation seed:
Code: Select all
GSGameSettings.GetValue("game_creation.generation_seed")
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
Re: Unique identifier for a game
I will try and explain what I am looking for.
When a new multi-player game of OpenTTD is started, there is some unique identifier (GUID etc.) that is generated that uniquely identifies that game from every other multi-player game of OpenTTD that is (or ever was) being played. This identifier should be generated at game start, and be saved/loaded so any time the game is ever played it can be identified as being the same game (perhaps the game is saved, and the server rebooted and the game loaded again).
I think I can make this identifier using a mixture of the hostname of the server, and the start time of the game - adding the code in my gamescript to save/load this information. To make this happen though I need access to the getenv() and time() functions from the system package (which I can't seem to access).
When a new multi-player game of OpenTTD is started, there is some unique identifier (GUID etc.) that is generated that uniquely identifies that game from every other multi-player game of OpenTTD that is (or ever was) being played. This identifier should be generated at game start, and be saved/loaded so any time the game is ever played it can be identified as being the same game (perhaps the game is saved, and the server rebooted and the game loaded again).
I think I can make this identifier using a mixture of the hostname of the server, and the start time of the game - adding the code in my gamescript to save/load this information. To make this happen though I need access to the getenv() and time() functions from the system package (which I can't seem to access).
Re: Unique identifier for a game
I already understood what a unique ID is, the more interesting question is how is a uid relevant to a game script, as one script instance is always associated with one game instance.
In other words, what's the use-case for a uid in a game script?
As for making one, indeed squirrel is quite limited. The proper solution to me would be to add such an ID in C++ to the game, and make the value available through an additional GameScript API function.
The TODO list at the wiki has a usecase for such uids too.
It may be worthwhile to have a look at a proper uuid library, if it's portable, it may be a better solution than a cook-your-own-pseudo-uid.
In other words, what's the use-case for a uid in a game script?
As for making one, indeed squirrel is quite limited. The proper solution to me would be to add such an ID in C++ to the game, and make the value available through an additional GameScript API function.
The TODO list at the wiki has a usecase for such uids too.
It may be worthwhile to have a look at a proper uuid library, if it's portable, it may be a better solution than a cook-your-own-pseudo-uid.
Being a retired OpenTTD developer does not mean I know what I am doing.
Re: Unique identifier for a game
Sorry, I should have specified what I was trying to do :-/.
My use case is that I am extracting data from the game using the gamescript API and storing the data in a database. Rather than clearing the database between runs, I would like to be able to store the data from lots of different games in the database so I can process many different game instances.
Thanks for the suggestion, I will look at making the change - I agree with not rolling my own UUID implementation, the hostname/starttime idea was me trying to find a way to do it in a gamescript that just used the Squirrel "system" functions (getenv() and time() - a combination of which should be enough for my purposes) rather than having to change the source code for the game.
Thanks a lot for your advice.
My use case is that I am extracting data from the game using the gamescript API and storing the data in a database. Rather than clearing the database between runs, I would like to be able to store the data from lots of different games in the database so I can process many different game instances.
Thanks for the suggestion, I will look at making the change - I agree with not rolling my own UUID implementation, the hostname/starttime idea was me trying to find a way to do it in a gamescript that just used the Squirrel "system" functions (getenv() and time() - a combination of which should be enough for my purposes) rather than having to change the source code for the game.
Thanks a lot for your advice.
Re: Unique identifier for a game
http://nogo.openttd.org/api/trunk/class ... 8066a0b5d0
This should be enough no?
This should be enough no?
Re: Unique identifier for a game
The system time is good - but I was hoping that I could get a little more identifying information. Perhaps I'll combine it with the randomisation seed for the map as well.
Re: Unique identifier for a game
Depending on your definition of 'same game', a md5 hash of all settings might work too.
I think it would be a nice addition for OpenTTD.
I think it would be a nice addition for OpenTTD.
Being a retired OpenTTD developer does not mean I know what I am doing.
Re: Unique identifier for a game
Whatever you do, it comes down to the question: Does a scenario have a single unique id, or does starting the same scenario multiple times result in different ids?
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
Re: Unique identifier for a game
Sounds like there are two different requirements here:
1. Some unique identifier (same settings will still generate a new id)
2. Settings hash (same settings will generate the same hash)
Interesting, I hadn't really considered the second scenario.
1. Some unique identifier (same settings will still generate a new id)
2. Settings hash (same settings will generate the same hash)
Interesting, I hadn't really considered the second scenario.
Re: Unique identifier for a game
The notion of "equal" has many different forms, and depending on what you want to achieve, you need a different one.
As such, it's not two requirements, it's two solutions for the same requirement. (And there are many more solutions, for example, a settings hash doesn't take the newgrf list or newgrf parameters into account.)
However, I think Frosch asked the right question to be answered first, is a scenario a savegame or something else?
As such, it's not two requirements, it's two solutions for the same requirement. (And there are many more solutions, for example, a settings hash doesn't take the newgrf list or newgrf parameters into account.)
However, I think Frosch asked the right question to be answered first, is a scenario a savegame or something else?
Being a retired OpenTTD developer does not mean I know what I am doing.
Re: Unique identifier for a game
.
Last edited by aidos on 07 Jun 2015 14:27, edited 1 time in total.
Re: Unique identifier for a game
For me - with the id generated at the start of the game, if you load a save of that game the id should still be the same, it's about the "instance" of the world that is being used.
Re: Unique identifier for a game
Sure, but when does a game start when you use a scenario?
(with "play scenario" or with "create scenario"?).
I am aware there isn't much to play when you press "create scenario", but if you pick that, "play scenario" will just copy the ID generated with "screate scenario", and the game you "play scenario" now will be the same game as the one you play next year.
Edit: FYI, there isn't much point in making completely blank messages, the usual form is to add "Edit: <more text>" lines at the end of the message, like I do here.
That way people can read both versions, and see what you changed or emphasized.
(with "play scenario" or with "create scenario"?).
I am aware there isn't much to play when you press "create scenario", but if you pick that, "play scenario" will just copy the ID generated with "screate scenario", and the game you "play scenario" now will be the same game as the one you play next year.
Edit: FYI, there isn't much point in making completely blank messages, the usual form is to add "Edit: <more text>" lines at the end of the message, like I do here.
That way people can read both versions, and see what you changed or emphasized.
Being a retired OpenTTD developer does not mean I know what I am doing.
Who is online
Users browsing this forum: No registered users and 19 guests