[SOLVED]:Next State skipping State

Game development with Board Game Arena Studio
Post Reply
User avatar
MikeIsHere
Posts: 137
Joined: 30 April 2020, 22:52

[SOLVED]:Next State skipping State

Post by MikeIsHere »

When I don't call nextState everything works fine but if I expliciatly call next state, then the next state I go to automatically goes to the next state after it without letting the player act

So if this is my States.php

Code: Select all

$machinestates = array(

    // The initial state. Please do not modify.
    1 => array(
        "name" => "gameSetup",
        "description" => "",
        "type" => "manager",
        "action" => "stGameSetup",
        "transitions" => array( "" => 2 )
    ),
    
    2 => array(
        "name" => "startState",
        "description" => "",
        "type" => "game",
        "action" => "stStartState",
        "updateGameProgression" => true,
        "transitions" => array("" => 200)

    ),

    // Note: ID=2 => your first state
    200=> array(
        "name" => "cutDeal",
        "description" => clienttranslate('Opponent must choose a card '),
        "descriptionmyturn" => clienttranslate('${you} must choose a card'),
        "type" => "multipleactiveplayer",
        "action" => "stCutDeal",
        "possibleactions" => array( "cutDeal"),
        "transitions" => array('done'=>3)
    ),

    3 =>array(
        "name" => "setDealer",
        "description" => "",
        "type" => "game",
        "action" => "stSetDealer",
        "transitions" => array('tie' => 2, 'winner'=>9)

    ),
    9 => array(
And I put nothing in the StartState function, then the game works as expected goes to step 200 where

Code: Select all

function stCutDeal() {
        // Just activate the selection
        $this->gamestate->setAllPlayersMultiactive();
    }
Then after all the players have chosen a card state 3 runs to set the Dealer for the game

However if I change my state 2 to something like

Code: Select all

"transitions" => array("cut" => 200)
and change startState to

Code: Select all

function stStartState () {
        $this->gamestate->nextState('cut');
 }
Then what happens is stCutDeal runs and the state stSetDealer also runs. I know this because I can put a var_dump("200 step") in stCutDeal and the error check in stSetDealer also runs and the game bombs

I do want to get to the point from step 2 where a choice is made based on game options

Code: Select all

"transitions" => array("cut" => 200, "auto"=>3)
Last edited by MikeIsHere on 29 June 2020, 11:19, edited 1 time in total.
User avatar
MikeIsHere
Posts: 137
Joined: 30 April 2020, 22:52

Re: Next State skipping State

Post by MikeIsHere »

I just want to add that I don't think the issue is related to this
Game "spontaneously" transition to a new state without user input
Make sure on php side you have no code after $this->gamestate->nextState(...) code. Because if you do accidentally have code that goes to another state it will cause another state transition without user interaction.

function selectField($field) {
self::checkAction ( 'selectField' );
if ($field!=0) $this->gamestate->nextState ( 'next' );
$this->gamestate->nextState ( 'last' ); // <-- here is missing else, so it will cause double state transition
}
Because again, I have only one line in my startState function
vincentt
Posts: 254
Joined: 01 September 2017, 17:25

Re: Next State skipping State

Post by vincentt »

Hi,

I would have suggested an action that trigger the next state...
Can you give your project name so we can give you a help on this (it will be quicker if we are able to see the whole code)
Thanks
User avatar
joezg
Posts: 70
Joined: 16 June 2011, 17:17

Re: Next State skipping State

Post by joezg »

Hi,
I'm pretty sure the problem is:

$this->gamestate->nextState( "" );

in setupNewGame function. Game goes automatically to state with id 2, so you must not call nextState in setupNewGame function.

Best,
Jurica
User avatar
MikeIsHere
Posts: 137
Joined: 30 April 2020, 22:52

Re: Next State skipping State

Post by MikeIsHere »

in setupNewGame function. Game goes automatically to state with id 2, so you must not call nextState in setupNewGame function.
Thank you this was it, and that line has been there from day one, :?
Post Reply

Return to “Developers”