Page 1 of 1

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

Posted: Mon Aug 30, 2021 1:17 am
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.

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

Posted: Mon Aug 30, 2021 8:16 pm
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.

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

Posted: Tue Sep 07, 2021 8:57 am
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?

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

Posted: Tue Sep 07, 2021 4:12 pm
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.

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

Posted: Mon Nov 29, 2021 4:17 pm
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.