[SOLVED] Store array as global variable
Posted: 03 May 2016, 12:51
Hi folks!
Today I'm facing a problem about how to deal with a multiplayer phase. I'm in a multiplayer state where all players must choose a card to play first. Once all players make their decision, then all cards are meld in player board. It is very similar to the game mecanism in 6nimmt.
So I want to keep track of who will play which card using an array as a global variable. First I want that array empty at the setup (let's call it $chosen_cards). Then when a player make is decision and his move is valid on server side, I want to update that array like this: (with $card an array representing the information about the chosen card). Then, when all players have made their choice, I jump to a game state where I read the contents of this array in order to make the play.
I've tried two things to do so so far:
#1: add 'chosen_card' as a global variable in self::initGameStateLabels and use the getter and setter: impossible because this mecanism can handle only scalar variables, not arrays
.
#2: initialise the variable as $this->chosen_card in material.inc.php: seems awkward to me because this file is there to stoke game material information, not current situation. Anyway, this solution fails because the array seems re-initialized each time I want to update it to resolve player move.
I think I could design a specific table in database to handle this but I feel that solution very overwhelming.
What solution do I get left before I have to do that?
Today I'm facing a problem about how to deal with a multiplayer phase. I'm in a multiplayer state where all players must choose a card to play first. Once all players make their decision, then all cards are meld in player board. It is very similar to the game mecanism in 6nimmt.
So I want to keep track of who will play which card using an array as a global variable. First I want that array empty at the setup (let's call it $chosen_cards). Then when a player make is decision and his move is valid on server side, I want to update that array like this:
Code: Select all
$chosen_cards[$player_id] = $cardI've tried two things to do so so far:
#1: add 'chosen_card' as a global variable in self::initGameStateLabels and use the getter and setter: impossible because this mecanism can handle only scalar variables, not arrays
#2: initialise the variable as $this->chosen_card in material.inc.php: seems awkward to me because this file is there to stoke game material information, not current situation. Anyway, this solution fails because the array seems re-initialized each time I want to update it to resolve player move.
I think I could design a specific table in database to handle this but I feel that solution very overwhelming.
What solution do I get left before I have to do that?