Page 1 of 1
getActivePlayerId() during setupNewGame
Posted: 29 April 2024, 05:34
by imralav
Dear fellow devs,
I am looking for a way to learn about the ID of first player to take a turn during
phase. At what point does the game engine decide who will the first player be?
I hoped that maybe
will make a difference. Unfortunately, it doesn't matter if I invoke the
before
or after it, I always get a NULL there, and I need it to be correctly set to first player because of reasons.
Best regards
Tomasz
Re: getActivePlayerId() during setupNewGame
Posted: 29 April 2024, 08:50
by RicardoRix
I'm not overly certain about the best way to do it, but...
You can make your own game state that after BGA's first state it goes to. Everything should be readable then.
Alternatively in the player table, I think it's the player_no or player_order field that has the information.
Re: getActivePlayerId() during setupNewGame
Posted: 29 April 2024, 09:20
by thoun
I just use this :
$firstPlayerId = intval(array_keys($players)[0]));
Re: getActivePlayerId() during setupNewGame
Posted: 29 April 2024, 10:17
by LeSteffen
Alternatively just query the DB:
$this->getUniqueValueFromDb("SELECT player_id FROM player WHERE player_no=1");
Re: getActivePlayerId() during setupNewGame
Posted: 29 April 2024, 10:48
by imralav
So we can safely assume that the order of players in provided array, as well as in the table, is also the order of the turn? Good, that helps a lot, thank you!
Re: getActivePlayerId() during setupNewGame
Posted: 29 April 2024, 10:51
by RicardoRix
it's the same thing.
Re: getActivePlayerId() during setupNewGame
Posted: 29 April 2024, 11:52
by imralav
Makes sense.
Also, this:
RicardoRix wrote: ↑29 April 2024, 08:50
I'm not overly certain about the best way to do it, but...
You can make your own game state that after BGA's first state it goes to. Everything should be readable then.
Alternatively in the player table, I think it's the player_no or player_order field that has the information.
is very creative, I like it, even though for my purposes it's an overkill, but I'll keep this pattern in mind for future. Thanks.