Page 1 of 1
Accessing gameinfos array in gameinfos.inc.php from mygame.game.php
Posted: 04 January 2017, 05:07
by Cowseye
Hi all,
Pardon me as I am new to BGA developer and still quite amateurish to PHP coding.
The default code of mygame.game.php has a few line of codes (from line 61 to line 78) that populate some basic information such as player color and if any favorite color among players.
However, this are some difficulties that I met in the default codes as part of project creation:
1. $gameinfos = self::getGameinfos(); in line 64
This segment cannot function as there were no such method stated anywhere. If we need to program our own, what should be added here?
2. $default_colors = $gameinfos['player_colors']; in line 65
I see 2 possbilities in this statement. One would be defining the information in getGameInfos() in line 64. The other would be using $gameinfos array stated in the gameinfos.inc.php.
However, I tried importing the gameinfos.inc.php in the header of mygame.game.php file like this:
include 'gameinfos.inc.php';
I added this line after the require_once stated at the start of the file.
But the setup still could not find $gameinfos array and reported an error that the values were null.
Could someone please enlighten me?
Regards,
Chris (Cowseye)
Re: Accessing gameinfos array in gameinfos.inc.php from mygame.game.php
Posted: 05 January 2017, 03:32
by Victoria_La
Are you saying you created a project and this code appeared or your wrote it? gameinfos that I have do not define colours, its just hard-coded
in initialisation routine. Unless you really needed to include this file I won't bother with it.
This is standard code:
Code: Select all
protected function setupNewGame($players, $options = array()) {
// Set the colors of the players with HTML color code
// The below is red/blue/yellow/purple
// The number of colors defined here must correspond to the maximum number of players allowed for the game
$default_colors = array (
"ff0000",
"0000ff",
"ffa500",
"4c1b5b"
);
$colors_copy = $default_colors;
// Create players
// Note: if you added some extra field on "player" table in the database (dbmodel.sql), you can initialize it there.
$sql = "INSERT INTO player (player_id, player_color, player_canal, player_name, player_avatar) VALUES ";
$values = array ();
foreach ( $players as $player_id => $player ) {
$color = array_shift($default_colors);
$player_name = $player ['player_name'];
$values [] = "('" . $player_id . "','$color','" . $player ['player_canal'] . "','" . addslashes($player_name) . "','" . addslashes($player ['player_avatar']) . "')";
}
$sql .= implode($values, ',');
$this->DbQuery($sql);
$this->reattributeColorsBasedOnPreferences($players, $colors_copy);
$this->reloadPlayersBasicInfos();
/**
* ********** Start the game initialization ****
*/
...
Re: Accessing gameinfos array in gameinfos.inc.php from mygame.game.php
Posted: 05 January 2017, 05:38
by Cowseye
Thanks for the reply. Yes, it came default with the project. But I figure out if I were to include the php just before accessing the array, it will work. Thanks.
Re: Accessing gameinfos array in gameinfos.inc.php from mygame.game.php
Posted: 06 January 2017, 23:38
by DrKarotte
When I created a new project several weeks ago I had these parts of non-working code, too. I have replaced them with the code of an earlier project. If I hadn't had this older project I probably would not have known what to do like Cowseye. Did the BGA crew changed something in the code?
Re: Accessing gameinfos array in gameinfos.inc.php from mygame.game.php
Posted: 10 January 2017, 02:51
by Victoria_La
Apparently they did. I think they changed framework in production (like added these API's) but not in studio. Can somebody send them a bug?
I don't have the new code to include as reference in a bug.
Re: Accessing gameinfos array in gameinfos.inc.php from mygame.game.php
Posted: 17 January 2017, 17:01
by Een
Sorry for the delay looking into this. Template for new projects was indeed broken (too recent for the current studio version).
I reverted to a compatible version. Here is the diff between versions, you need to undo those changes to get things working on the projects created with the wrong template.
Code: Select all
--- emptygame.game.php (révision 13892)
+++ emptygame.game.php (copie de travail)
@@ -22,7 +22,7 @@
class EmptyGame extends Table
{
- function EmptyGame( )
+ function __construct( )
{
@@ -61,7 +61,8 @@
// Set the colors of the players with HTML color code
// The default below is red/green/blue/orange/brown
// The number of colors defined here must correspond to the maximum number of players allowed for the gams
- $default_colors = array( "ff0000", "008000", "0000ff", "ffa500", "773300" );
+ $gameinfos = self::getGameinfos();
+ $default_colors = $gameinfos['player_colors'];
// Create players
// Note: if you added some extra field on "player" table in the database (dbmodel.sql), you can initialize it there.
@@ -74,7 +75,7 @@
}
$sql .= implode( $values, ',' );
self::DbQuery( $sql );
- self::reattributeColorsBasedOnPreferences( $players, array( "ff0000", "008000", "0000ff", "ffa500", "773300" ) );
+ self::reattributeColorsBasedOnPreferences( $players, $gameinfos['player_colors'] );
self::reloadPlayersBasicInfos();
/************ Start the game initialization *****/
@@ -173,7 +174,7 @@
...
// Notify all players about the card played
- self::notifyAllPlayers( "cardPlayed", clienttranslate( '${player_name} played ${card_name}' ), array(
+ self::notifyAllPlayers( "cardPlayed", clienttranslate( '${player_name} plays ${card_name}' ), array(
'player_id' => $player_id,
'player_name' => self::getActivePlayerName(),
'card_name' => $card_name,