Automate player actions descrepencies

Game development with Board Game Arena Studio
Post Reply
User avatar
pickardj79
Posts: 17
Joined: 26 July 2020, 04:34

Automate player actions descrepencies

Post by pickardj79 »

I'm trying to automate some player actions to quickly modify and return to a set game state (yes, I know about the saved state slots - not quite what I need). I think this will allow for rapid iteration on minor game state manipulations. In addition to learning a bit about the state machine, I've run into a few head scratchers.

The first one is something people already know but I can't find documented anywhere. The game breaks if in multipleactiveplayer state and the "automated" code calls a function that uses self::getCurrentPlayerId();. When that function is called by way of an ajax request / player action (non-automated), the self::getCurrentPlayerId() works correctly. I wonder if there's a way to set the active player in multipleactiveplayer so that a subsequent call to self::getCurrentPlayerId() returns the desired player? That is to say, how does the game framework handle current player for ajax / player actions in multi-active?

The second one is really a ... don't know. Lost a couple hours to this one. I'm comparing a int pulled from the db to an int stored as a gameStateValue. The int from the db gets pulled as a string (self::getObjectListFromDB). The gameStateValue is initially set as an int (from material.inc.php) but in "normal" mode, when the game is played through the UI, it's gotten as a string. However, when that same function is called in my "automated" mode, that gameStateValue is pulled as an int. The comparison is using !== so it fails, always. I'm not sure why it's using !==. Perhaps I should just switch it to != and allow php to handle types. Either way, a couple questions:

* Are all values pulled from the db pulled as strings?
* Why would the gameStateValue be a string in one case but int in the other?

Help or speculation much appreciated!
User avatar
Tisaac
Posts: 2743
Joined: 26 August 2014, 21:28

Re: Automate player actions descrepencies

Post by Tisaac »

I remember a post here about type inconsitency when pulling from db and I thought Een told he solved it but maybe there is still a similar issue somewhere else.
In any case, I almost never use type equality in my php to avoid this, or enforce type conversion when I nees it.

For the multiplayer state, the thing is that the game in itself is not instanciated with a specific player to run it only once and then send notifs through the new state. That means current player has no meaning in automated action and in args (you should use private if needed). On a ajax call however, my guess is that the game is instanciated with the player that run the ajax query.
User avatar
pickardj79
Posts: 17
Joined: 26 July 2020, 04:34

Re: Automate player actions descrepencies

Post by pickardj79 »

Ah yes - the gameStateValues are pulled from the DB, aren't they? I think I remember reading that somewhere. Good illustration of the law of leaky abstractions :lol: ! Switching to removing type equalities...

I'll have to find workarounds when I need a current player during my automation. Might just be passing player_ids into functions that need them. Thanks for the response!

--- EDIT ---
Yup - just saw a note on the troubleshooting page about strings coming from the database: https://boardgamearena.com/doc/Troubles ... g_I_expect.
User avatar
Draasill
Posts: 197
Joined: 26 April 2020, 00:00

Re: Automate player actions descrepencies

Post by Draasill »

I wrapped most DB calls into objects, which casts data (as "int" for example), so I can use type hints and strict comparison everywhere; otherwise it's quite frustrating.
Post Reply

Return to “Developers”