[QUES] Get Each Game in Game History

For my mod I’d like to have a weekly event that pays for each game in your game history. For this I’d need to be able to get an array of each game in the player’s game history and then do something for each one.

For each game I’d like to get it’s rating and add that to the weekly payment amount (times 100) and then payout the grand total to the user.

Also if possible, I’d like to also check if the game has been taken off the market, and only give you money in that scenario.

To be clear, I checked the mod-api wiki, and I couldn’t find any way to access the player’s game history. I could only access information on the in-development game.

You’re requesting…?

Sorry, I wasn’t entirely clearly what I meant. I updated the main post with a bit more info.

You’ll find the data in: GameManager.company.gameLog

This is an array containing elements of type “Game”.

Querying Game.state you can check what state a game has.

notStarted: 0,
concept: 1,
development: 2,
publishing: 3,
released: 4

Thanks a bunch. That should help me with the bulk of this mod.

1 Like

You’re welcome. :slight_smile:

Now I do actually have a couple more questions.
Can I get the actual info on a game using this? I mean like is there a way to grab the games rating?

Something like this:
GameManager.company.gameLog.game.rating

No, game log is an array.

You can do:

GameManager.company.gameLog[0].score // Score being what you implied with rating.
// and 0 being the first element in the array

If you wanted to find a specific game in the array you would need to iterate through each member to find one.
As far as I know with javascript the best way is:

var gameLog = GameManager.company.gameLog;
var gameTitle = "My Game";

function (gameLog, gameTitle) {
	var game;
	for (var i = 0; i < gameLog.length && game == "undefined"; i++) {
		if (gameTitle == gameLog[i].title) {
			game = gameLog.[i];
		}
	}
  return game;
}

However this would not work as intended if the game title was the same in two games.
But you get the idea of searching the arrays.

If you don’t know a lot about arrays and arrays containing objects it would be worth doing a little research on them.

1 Like