onLeavingState and args

Game development with Board Game Arena Studio
Post Reply
User avatar
tarini
Posts: 45
Joined: 11 July 2013, 22:36
Location: italy
Contact:

onLeavingState and args

Post by tarini »

Looking inside game.js file I discovered that inside onLeavingState callback I cannot access state args and it could have sense.

BUT

How can I implement this game mechanics without creating an empty new game state?

Suppose you have a simple game turn game divided in phase. Each phase has a "captain" that is the player that plays the first turn of the phase (exacly as in Puerto Rico).
The progression of "captain" token is not linear but it has to be recalculated every phase (it could happen that the previous captain became also the next captain).
Inside user panels I want to put a little icon that show who's the current captain.

After turn state (activeplayer), there is a endTurn (game) state that calculates if every player has played (if not it's not, it go back to turn) and go to nextPhase (game). Inside my nextPhase I calculate who is the next captain, activate him and return to turn state allows him to play.

I want to notify the clients about the new captain but i can't do this inside onEnteringState because it's to early (i'll receive old captain) neither inside onLeavingState because I have no information because args are not available.

Should I create an empty state just to get this information?
Do I have to retrieve this inside turn state? It's not redundant?
User avatar
pikiou
Posts: 389
Joined: 03 October 2011, 05:36

Re: onLeavingState and args

Post by pikiou »

I've encountered this lack of feature as well and what I do is I always save state arguments in onEnteringState for them to be used in onLeavingState.
But it's too obvious an answer, I must have misunderstood your request.
User avatar
tarini
Posts: 45
Joined: 11 July 2013, 22:36
Location: italy
Contact:

Re: onLeavingState and args

Post by tarini »

Yes, but it's my fault.
I'll try to recap.

If I do some calculations inside stMyStatus and i need to pass results to the clients without use another state, I can't use javascript change state callback because custom args are available only BEFORE my calculations. I need to send a notification and create a new listener on the client.

Am I right?
User avatar
pikiou
Posts: 389
Joined: 03 October 2011, 05:36

Re: onLeavingState and args

Post by pikiou »

Now I understand! You're right: during the very same state, the "args" method can be called multiple times before and/or after the "action" method. This can be very misleading! And I'm not sure which call makes it to the players. It's even more random in multipleactiveplayer states.
So you either need to use notifications or to create another state, which sourisdudesert once told me is his preferred solution.

Since this bug wasn't fixed when I reported it (admins have done so much elsewhere, no blame intended) I edited the wiki for new devs to be aware of this time consuming trap.
Post Reply

Return to “Developers”