[Genhis] [1.1.38] game.finished only lasts for a single tick

This subforum contains all the issues which we already resolved.
User avatar
raiguard
Factorio Staff
Factorio Staff
Posts: 615
Joined: Wed Dec 13, 2017 8:29 pm
Contact:

[Genhis] [1.1.38] game.finished only lasts for a single tick

Post by raiguard »

I could be misunderstanding how this is supposed to work, but so far as I can tell, game.finished is supposed to tell you if the game was finished in the past. However, reading it after the tick where the game was finished will always return false.

Reproduction:
1. Stick the following in a mod's control.lua:

Code: Select all

script.on_event(defines.events.on_tick, function(e)
  if game.tick == 10 then
    game.set_game_state{
      game_finished = true,
      player_won = true,
      can_continue = true,
      victorious_force = game.forces.player,
    }
    game.print(game.tick.." "..tostring(game.finished))
  elseif game.tick == 20 then
    game.print(game.tick.." "..tostring(game.finished))
  end
end)
2. Start a new game
3. Click "continue" on the game finished screen
4. Wait a second
5. Observe that it returns true on tick 10, but false on tick 20.
Don't forget, you're here forever.
Honktown
Smart Inserter
Smart Inserter
Posts: 1045
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: [1.1.38] game.finished only lasts for a single tick

Post by Honktown »

Addition:

Code: Select all

/c
game.set_game_state{
	game_finished = true,
	can_continue = true,
	victorious_force = game.forces.enemy
}
If player_won is nil or false, the game can keep being "finished" but doesn't stay at finished. victorious_force has no effect on this.
I have mods! I guess!
Link
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5304
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [1.1.38] game.finished only lasts for a single tick

Post by Klonan »

Well, the code hasn't changed in 6 years, I am not sure what the intent was behind it

Furthermore, the 'Continue' button in the 'Finished game' GUI specifically resets the finished state to false.

So I am not sure what we want here,

What is the usecase for checking game.finished?
User avatar
raiguard
Factorio Staff
Factorio Staff
Posts: 615
Joined: Wed Dec 13, 2017 8:29 pm
Contact:

Re: [1.1.38] game.finished only lasts for a single tick

Post by raiguard »

I would expect it to remain true after a force wins the game. The game appears to already track this internally, since if you call game.set_game_state() again after the first force wins, it doesn't pop up the victory box again.

My usecase is I only want to play the K2 victory audio once, when the game is actually finished for the first time. I could easily track this in global, but I tried to use this property first since it seemed like it was supposed to work this way.
Don't forget, you're here forever.
Genhis
Factorio Staff
Factorio Staff
Posts: 709
Joined: Wed Dec 24, 2014 8:19 am
Contact:

Re: [Genhis] [1.1.38] game.finished only lasts for a single tick

Post by Genhis »

Thanks for the report. For compatibility reasons, we decided not to fix game.finished but rather clarify its behavior - it is true only while the victory screen is shown.

Additionally, I added LuaGameScript::finished_but_continuing which is true after players press "Continue", and LuaGameScript::reset_game_state().

These changes will be included in the next release.
Post Reply

Return to “Resolved Problems and Bugs”