Page 1 of 1

Possible bug in New Game Template

Posted: 08 September 2024, 21:04
by sm11963
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":

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");
While the .view.php that was created when I created the new game was this (note there is no 'Place your code below' comment):

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)
  	{
        //
  	}
}

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:

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  ************/
  	}

...
SO it seems like the new game template needs to be fixed to be flushed out for the `build_page` method?

Re: Possible bug in New Game Template

Posted: 09 September 2024, 09:31
by thoun
We want to get rid of the HTML building on PHP file in the end, that's why the template was cleaned, there's no plan to put them back.
Can you add the 2 missing lines in the Hearts tutorial instead? Until we have the time to rewrite that part of the tutorial with front-side HTML generation.

Re: Possible bug in New Game Template

Posted: 09 September 2024, 15:00
by imralav
thoun wrote: 09 September 2024, 09:31 We want to get rid of the HTML building on PHP file in the end, that's why the template was cleaned, there's no plan to put them back.
That's interesting and a step in the right direction. Is there any kind of roadmap when it comes to BGA development, especially parts that affect the developing of the games themselves? Recently we've got autowired actions, which are a thing of beauty, now this. I am excited for the future.

Re: Possible bug in New Game Template

Posted: 09 September 2024, 18:52
by sm11963
thoun wrote: 09 September 2024, 09:31 We want to get rid of the HTML building on PHP file in the end, that's why the template was cleaned, there's no plan to put them back.
Can you add the 2 missing lines in the Hearts tutorial instead? Until we have the time to rewrite that part of the tutorial with front-side HTML generation.
Sounds good, I'll take a look at that tonight. I think I also found another issue in the tutorial as well where it uses undefined UserPreferences. UserPreferences aren't even used in the published version of Hearts, so I think I'll just remove that usage as it probably doesn't add anything to the tutorial.

Re: Possible bug in New Game Template

Posted: 10 September 2024, 04:59
by sm11963
@thoun it actually looks like you added this to the Hearts tutorial in June:

Code: Select all

const card_style = this.getGameUserPreference(100);
diff here:
https://en.doc.boardgamearena.com/index ... ldid=21683

I just removed this from the tutorial because with a newly created game no user preferences were loading. I also don't know where the style for `card_{card_style}` would be coming from (did a quick search and couldn't find anything, but I'm also brand new).

Any reason to keep the UserPreference reference in the tutorial?

Re: Possible bug in New Game Template

Posted: 10 September 2024, 05:50
by sm11963
While I'm discussing it here, I ended up making a handful of small fixes to the tutorial so that it all works. I just went through it all and with my edits everything works as described. Would appreciate a quick review of all the changes I made, just to double check:

https://en.doc.boardgamearena.com/index ... ldid=22429

Re: Possible bug in New Game Template

Posted: 10 September 2024, 07:44
by thoun
I'm fine with your changes, thanks!