How to implement a common step where I need to roll 2 dice

Game development with Board Game Arena Studio
Post Reply
User avatar
stefano
Posts: 89
Joined: 28 June 2011, 22:18

How to implement a common step where I need to roll 2 dice

Post by stefano »

Hello,

where can I read an example of creating a common initial step where I need to roll 2 dice and position 2 tokens depending on the result of the dice?
The roll must be common to all the players, un-repeatable (e.g. if I press F5) and the result must be applied to all players.

I'm trying to implement the game snowtime.

Thanks
User avatar
Tisaac
Posts: 2743
Joined: 26 August 2014, 21:28

Re: How to implement a common step where I need to roll 2 dice

Post by Tisaac »

stefano wrote: 16 October 2020, 07:41 Hello,

where can I read an example of creating a common initial step where I need to roll 2 dice and position 2 tokens depending on the result of the dice?
The roll must be common to all the players, un-repeatable (e.g. if I press F5) and the result must be applied to all players.

I'm trying to implement the game snowtime.

Thanks
This is quite simple actually, you just need a gamestate that will do the roll on the backend by taking a random value, and then dispatch notifications to all players to do the animations on the client of players.
User avatar
stefano
Posts: 89
Joined: 28 June 2011, 22:18

Re: How to implement a common step where I need to roll 2 dice

Post by stefano »

Would you mind giving me some snippets of code?
User avatar
stefano
Posts: 89
Joined: 28 June 2011, 22:18

Re: How to implement a common step where I need to roll 2 dice

Post by stefano »

I'm using this member, but I'm getting different results for the players:

function argPlaceFruit()
{
$result1 = rand(1, 6);
$result2 = rand(1, 6);
return array(
'diceresult1' => $result1,
'diceresult2' => $result2,
);
}


2 => array(
"name" => "PlaceFruit",
"description" => clienttranslate("Rolling the dice"),
"type" => "game",
"action" => "stPlaceFruit",
"args" => "argPlaceFruit",
"updateGameProgression" => true,
"transitions" => array( "PlayersTurn" => 3 )
),
User avatar
Tisaac
Posts: 2743
Joined: 26 August 2014, 21:28

Re: How to implement a common step where I need to roll 2 dice

Post by Tisaac »

stefano wrote: 16 October 2020, 09:33 Would you mind giving me some snippets of code?
Something like this :

Code: Select all

function stRollDice(){
		$face = bga_rand(1, 6);
 		$this->setGameStateValue('diceFace', $face);
		$this->gamestate->nextState('');
	}

function argMyState(){
  return [
     'dice' => this->getGameStateValue('diceFace')
   ]
}
With a state machine :

Code: Select all

    ST_ROLL_DICE => [
      "name" => "rollDice",
      "description" => '',
      "type" => "game",
      "action" => "stRollDice",
      "transitions" => ['' => ST_MY_STATE]
    ],
    
    ST_MY_STATE => [
       ....
       "arg" => "argMyState"
   ]
User avatar
stefano
Posts: 89
Joined: 28 June 2011, 22:18

Re: How to implement a common step where I need to roll 2 dice

Post by stefano »

Working now... the trick was to do it into the "st" function and not in the "arg" one... I used one single state in the machine, passing the value from st to arg function using the global labels
Post Reply

Return to “Developers”