getActivePlayerId() during setupNewGame

Game development with Board Game Arena Studio
Post Reply
imralav
Posts: 23
Joined: 02 February 2024, 08:56

getActivePlayerId() during setupNewGame

Post by imralav »

Dear fellow devs,

I am looking for a way to learn about the ID of first player to take a turn during

Code: Select all

setupNewGame
phase. At what point does the game engine decide who will the first player be?

I hoped that maybe

Code: Select all

self::activeNextPlayer()
will make a difference. Unfortunately, it doesn't matter if I invoke the

Code: Select all

self::getActivePlayerId()
before

Code: Select all

activeNextPlayer()
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
User avatar
RicardoRix
Posts: 2132
Joined: 29 April 2012, 23:43

Re: getActivePlayerId() during setupNewGame

Post 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.
User avatar
thoun
Posts: 1199
Joined: 10 December 2020, 22:25

Re: getActivePlayerId() during setupNewGame

Post by thoun »

I just use this :
$firstPlayerId = intval(array_keys($players)[0]));
User avatar
LeSteffen
Posts: 42
Joined: 13 July 2020, 15:32

Re: getActivePlayerId() during setupNewGame

Post by LeSteffen »

Alternatively just query the DB:
$this->getUniqueValueFromDb("SELECT player_id FROM player WHERE player_no=1");
imralav
Posts: 23
Joined: 02 February 2024, 08:56

Re: getActivePlayerId() during setupNewGame

Post 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!
User avatar
RicardoRix
Posts: 2132
Joined: 29 April 2012, 23:43

Re: getActivePlayerId() during setupNewGame

Post by RicardoRix »

it's the same thing.
imralav
Posts: 23
Joined: 02 February 2024, 08:56

Re: getActivePlayerId() during setupNewGame

Post 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.
Post Reply

Return to “Developers”