Page 1 of 1

Change states.inc.php without breaking ongoing games

Posted: 30 January 2021, 19:05
by Crazyboog
Hi,

Is there anyway to add a state in the states.inc.php file without breaking all the ongoing games during the deployment?

My specific use case is that I would like to add an "activeplayer" state that can be reached after an existing "game" state. In the game.php file I would like to only transition to the new state if it exists, that is, if the game has started after the new code version was deployed.

Something like

Code: Select all

if (state 32 exists) {
	$this->gamestate->nextState("chooseShowHand");
} else {
	$this->gamestate->nextState("endHand");
}
I tried to use the self::checkAction('chooseShowHand', FALSE) method but it does not seem to work during the execution of a "game" state.

An other option I have in mind is to check the current game version and define which transition to do based on that (like the upgradeTableDb() function).

Please find below the two states I mention above.

EXISTING game STATE

Code: Select all

31 => array(
        "name" => "endBetRound",
        "description" => "",
        "type" => "game",
        "action" => "stEndBet",
        "transitions" => array("nextBetRound" => 30, "chooseShowHand" => 32, "endHand" => 25)
    ),

NEW activeplayer STATE

Code: Select all

32 => array(
        "name" => "chooseShowHand",
        "description" => clienttranslate('${actplayer} decides if she/he wants to reveal her/his hand'),
        "descriptionmyturn" => clienttranslate('Do you want to reveal your hand ${you}?'),
        "type" => "activeplayer",
        "possibleactions" => array("chooseShowHand"),
        "transitions" => array("chooseShowHand" => 25, "zombiePass" => 98)
    ),

Re: Change states.inc.php without breaking ongoing games

Posted: 30 January 2021, 19:53
by paramesis
I have been able to add states to new deployed versions of a game without disrupting existing games, as long as the existing states and indices are preserved. Existing games can make use of these new states. In your example, the logical statement (state 32 exists) would always be true after the new version is deployed.

If the existing games are not able to properly use the new states due to a change in the database, the database for existing games should be modified to be compatible as needed using the upgradeTableDb function. Since you mentioned this function, it's important to note that the DB version will only ever be different from the latest version once, when the game is first loaded after the update.

Re: Change states.inc.php without breaking ongoing games

Posted: 30 January 2021, 22:37
by Crazyboog
Oh yes, you're right, it does not seem to break current games. I was sure that the states.inc.php was loaded only once at the beginning of the game but it seems not :).

Thanks