Hey folks, I was following the Hearts tutorial verbatim yesterday and found that the step that has you modify the .view.php results in an error because `$players` is not defined.
The tutorial says to "In .view.php insert this code after 'Place your code below' comment":
While the .view.php that was created when I created the new game was this (note there is no 'Place your code below' comment):
As such, adding the code from the tutorial results in an error that `$players` is not defined.
Looking at the full Hearts sourcecode on github, it seems that the initial template for a new game should be more like:
SO it seems like the new game template needs to be fixed to be flushed out for the `build_page` method?
The tutorial says to "In .view.php insert this code after 'Place your code below' comment":
Code: Select all
$template = $this->getGameName() . "_" . $this->getGameName();
$directions = array( 'S', 'W', 'N', 'E' );
// this will inflate our player block with actual players data
$this->page->begin_block($template, "playerhandblock");
foreach ( $players as $player_id => $info ) {
$dir = array_shift($directions);
$this->page->insert_block("playerhandblock", array ("PLAYER_ID" => $player_id,
"PLAYER_NAME" => $players [$player_id] ['player_name'],
"PLAYER_COLOR" => $players [$player_id] ['player_color'],
"DIR" => $dir ));
}
// this will make our My Hand text translatable
$this->tpl['MY_HAND'] = $this->_("My hand");
Code: Select all
/**
* @property tutorialheartssmiller $game
*/
class view_tutorialheartssmiller_tutorialheartssmiller extends game_view
{
/**
* Returns the game name. Do not modify.
*/
protected function getGameName()
{
// Used for translations and stuff. Please do not modify.
return "tutorialheartssmiller";
}
/**
* Main view function.
*/
public function build_page($viewArgs)
{
//
}
}
Looking at the full Hearts sourcecode on github, it seems that the initial template for a new game should be more like:
Code: Select all
...
/**
* Main view function.
*/
public function build_page($viewArgs)
{
// Get players & players number
$players = $this->game->loadPlayersBasicInfos();
$players_nbr = count( $players );
/**
* ********* Place your code below: ***********
*/
/*********** Do not change anything below this line ************/
}
...