Mod API Reference:Client TurnAdvanced
Jump to navigation
Jump to search
Put the function in a file named Client_TurnAdvanced.lua:
function Client_TurnAdvanced(game, previousNumberOfTurns) end
The client calls this hook when it loads or refreshes a game that has more turns than the last time this device showed it. That includes:
- a turn that advances while the player has the game open
- turns that advanced while the player was away, which the hook sees when they next open the game
| Argument | Type | Description |
|---|---|---|
game |
ClientGame | Information about the game. game.Game.NumberOfTurns is the number of turns now.
|
previousNumberOfTurns |
number | How many turns the game had the last time this device showed it. |
Notes:
- If several turns advanced, the hook is called once. Compare
game.Game.NumberOfTurnswithpreviousNumberOfTurnsto see how many. - It isn't called the first time a device shows a game, since there's nothing to compare against.
- It isn't called when the number of turns goes down, such as when a single-player level is restarted.
- The device remembers each game's turn count for each signed-in player. A player who views the game on two devices gets the hook on each of them.
- It runs after Client_GameRefresh.
It works well with UI.SetMenuBadge and Mod.ClientStorage. For example, this shows how many turns are new until the player opens the mod's menu:
-- Client_TurnAdvanced.lua
function Client_TurnAdvanced(game, previousNumberOfTurns)
UI.SetMenuBadge(tostring(game.Game.NumberOfTurns - previousNumberOfTurns));
end
-- Client_PresentMenuUI.lua
function Client_PresentMenuUI(rootParent, setMaxSize, setScrollable, game, close)
UI.SetMenuBadge(nil);
...
end