There is no official function to load the content returned from getAllDatas.
You can get basic player information using $this->loadPlayersBasicInfos() but it won't have the 'nbsat' property you need.
In setupNewGame you should set a global (See the USE GLOBALS paragraph in
http://en.studio.boardgamearena.com/#!d ... e.game.php.) or a new MySQL table with your globals.
I have my own ugly way. I serialize various php variables containing all the data I need to run the game. It makes everything rather simple and as optimized.
In dbmodel.sql:
Code: Select all
CREATE TABLE IF NOT EXISTS `vardb` (
`name` varchar(250) NOT NULL,
`value` VARCHAR( 7000 ) NOT NULL,
PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Then in yourgame.inc.php:
Code: Select all
function varFromDB() {
$names = Array();
foreach (func_get_args() as $nameList) {
$names = array_merge($names, (array)$nameList);
}
$nameConditions = Array();
foreach ($names as $name) {
$nameConditions[] = "name='" . mysql_escape_string($name) . "'";
}
$variables = self::getCollectionFromDB('SELECT name, value FROM vardb WHERE ' . implode(' OR ', $nameConditions), true);
$vars = array_fill_keys($names, null);
foreach ($variables as $name => $value) {
$vars[$name] = unserialize($value);
}
return $vars;
}
function varToDB($variables) {
foreach ($variables as $variable => &$value) {
$value = "('" . mysql_escape_string($variable) . "', '" . mysql_escape_string(serialize($value)) . "')";
}
unset($value);
self::DbQuery('REPLACE INTO vardb (name, value) VALUES ' . implode(', ', $variables));
}
In setupNewGame:
Code: Select all
$game = Array('endOfGame' => false, 'blueTokensLeft' => 8);
$playerList = self::loadPlayersBasicInfos();
foreach($playerList as $player_id => &$player) {
$player = Array(
'deniers' => 0,
'boardPieces' => Array(),
) + $player;
}
unset($player);
$this->varToDB(compact('game', 'playerList')); //Saved $game as well as $playerList in the database
And anytime I need $game or $playerList I just fetch them from the DB:
Code: Select all
extract($this->varFromDB('game', 'playerList'));
//Do whatever with $game and $playerList, let's say we modified $game
$this->varToDB(compact('game')); //I only save $game
To answer your last post:
getAllDatas() gets called when someone loads the table for the first time after its start, or refreshed his browser. Just like the content of yourgame.view.inc.php
Once the request is answered, $this is destroyed.
When a user sends an action, a new request is formulated and $this is constructed again. Only this time there is no call to getAllDatas() so your data is gone.
1) getAllDatas() is only meant to send data for the browser interface to show the state of the game.
2) if you want persistent data, the answer is above (globals or DB).