I'm having some trouble implementing my first couple game states. The first state is a "game" state that simply places a set number of character elements in a wrapper beneath the title message area so that the players can choose from them. That transitions to an "activeplayer" state where the player chooses a character.
The problem I'm having is that when the game loads into the "activeplayer" state, the character divs are no longer in the wrapper. Or anywhere else. The relevant code:
states.php -
game.php -
game state argument -
game state action -
player action -
game.js, onEnteringState -
FWIW, the console also fails to log 'Entering state: characterInit'.
I know the divs are getting placed, because if I comment out the state transition from "characterInit" to "chooseCharacter", I can see the divs when I load the game and the state is logged to the console, but of course nothing happens next because it's now an inert state.
For my life I can't figure out what's happening to the divs between states.
The problem I'm having is that when the game loads into the "activeplayer" state, the character divs are no longer in the wrapper. Or anywhere else. The relevant code:
states.php -
Code: Select all
2 => array(
"name" => "characterInit",
"description" => "",
"type" => "game",
"args" => "argCharacterInit",
"action" => "stCharacterInit",
"transitions" => array("characterInit" => 3)
),
3 => array(
"name" => "characterSelection",
"description" => clienttranslate('${actplayer} must choose a character'),
"descriptionmyturn" => clienttranslate('${you} must choose a character'),
"type" => "activeplayer",
"possibleactions" => array("chooseCharacter"),
"transitions" => array("chooseCharacter" => 4)
game state argument -
Code: Select all
function argCharacterInit() {
return array(
'available_characters' => $this->getGlobalVariable('available_characters'),
);
}
Code: Select all
function stCharacterInit() {
//$this->gamestate->nextState('characterInit');
}
Code: Select all
function chooseCharacter($character) {
self::checkAction('chooseCharacter');
$player_id = self::getActivePlayerId();
self::DbQuery("UPDATE player SET `character`='$character' WHERE player_id='$player_id'");
self::notifyAllPlayers( "chooseCharacter", clienttranslate('${player_name} chooses ${character}'), array(
'player_name' => self::getActivePlayerName(),
'character' => $this->characters[$character]['description'],
'character_div' => "character_{$character}"
));
$this->gamestate->nextState('chooseCharacter');
}
Code: Select all
case 'characterInit':
for (let character_id of args.args.available_characters) {
let character = this.gamedatas.characters[character_id];
let bg_pos = character['x_y'];
dojo.place(this.format_block('jstpl_character', {
type : character_id,
extra_class : "character_select",
charX : bg_pos[0],
charY : bg_pos[1],
extra_style : "margin-top: 5px; margin-right: 5px; position: relative",
}), 'character_selection');
let html = `<div style="margin-bottom: 5px;"><strong>${character['description']}</strong></div>
<p>${character['flavor']} - ${character['effect']}</p>
<p>Starting Water/Psych: ${character['water_psych']}</p>
<span>Home Crag: ${character['home_crag']}</span>
<span style="font-size: 10px; white-space: nowrap;"><i>${character['translation']}</i></span>`;
this.addTooltipHtml(`character_${character_id}`, html, 1000);
}
break;
case 'characterSelection':
dojo.query('.character_select').connect('onclick', this, 'onChooseCharacter');
break;
I know the divs are getting placed, because if I comment out the state transition from "characterInit" to "chooseCharacter", I can see the divs when I load the game and the state is logged to the console, but of course nothing happens next because it's now an inert state.
For my life I can't figure out what's happening to the divs between states.