Invalid 'args' method

Game development with Board Game Arena Studio
User avatar
QuasarDuke
Posts: 18
Joined: 22 March 2020, 00:46

Invalid 'args' method

Post by QuasarDuke »

Code: Select all

25/01 12:27:02 [error] [T142255146] [89539151/Pranshu Jain] Error (1213) while processing SQL request: Deadlock found when trying to get lock; try restarting transaction - Request: SELECT player_id, player_is_multiactive FROM player
26/01 19:43:45 [error] [T140498875] [87564005/PancakeArchduke] Unexpected exception: Invalid 'args' method for state 31: argPlayableCards
#0 /var/tournoi/release/tournoi-210121-0943/www/game/module/table/gamestate.game.php(129): Gamestate->loadStateArgs()
#1 /var/tournoi/release/tournoi-210121-0943/www/game/module/table/table.game.php(156): Gamestate->state()
#2 /var/tournoi/release/tournoi-210121-0943/www/view/common/game.view.php(438): Table->getAllTableDatas()
#3 /var/tournoi/release/tournoi-210121-0943/www/view/common/game.view.php(362): game_view->post_generate()
#4 /var/tournoi/release/tournoi-210121-0943/www/view/common/ebg.view.php(23): game_view->generate_content()
#5 /var/tournoi/release/tournoi-210121-0943/www/include/webActionCore.inc.php(286): ebg_view->generate()
#6 /var/tournoi/release/tournoi-210121-0943/www/index.php(247): launchWebAction()
#7 {main}
boardgamearena.com/9/ninetynine?table=140498875
Why would I be getting an error like this? Note that the args method did not previously exist, then I rolled out a new version of the game which contained it (method added in ninetynine.game.php and in the states.inc.php)
User avatar
Victoria_La
Posts: 665
Joined: 28 December 2015, 20:55

Re: Invalid 'args' method

Post by Victoria_La »

Are you calling getCurrentPlayerId from args methd? What is the code for it?
User avatar
QuasarDuke
Posts: 18
Joined: 22 March 2020, 00:46

Re: Invalid 'args' method

Post by QuasarDuke »

Code: Select all

function argPlayableCards() {
        $player_id = self::getActivePlayerId();
        return array(
            '_private' => array(
                'active' => array(
                    'playableCards' => self::getPlayableCards($player_id)
                )    
            )    
        );   
    }  
User avatar
QuasarDuke
Posts: 18
Joined: 22 March 2020, 00:46

Re: Invalid 'args' method

Post by QuasarDuke »

Code: Select all

       // Return the list of valid playable cards in the given player's hand
    function getPlayableCards($playerId) {
        $cardsInHand = $this->cards->getPlayerHand($playerId);
        $currentTrickSuit = $this->getFirstPlayedSuit();
        if ($currentTrickSuit == null) {
            // All cards in the hand are valid to play
            return $cardsInHand;
        }
        // If we have cards in our hand of the led suit, return those
        $cardsOfLedSuit = array_filter($cardsInHand, function ($card) use ($currentTrickSuit) {
            return $card['type'] == $currentTrickSuit;
        });
        if (count($cardsOfLedSuit) == 0) {
            return $cardsInHand;
        }
        return $cardsOfLedSuit;
    }
   
User avatar
Victoria_La
Posts: 665
Joined: 28 December 2015, 20:55

Re: Invalid 'args' method

Post by Victoria_La »

You probably made a typo in args method name, what is your state 31?
User avatar
QuasarDuke
Posts: 18
Joined: 22 March 2020, 00:46

Re: Invalid 'args' method

Post by QuasarDuke »

I do not believe it was a typo - all my local testing worked perfectly. Here is a snippet from my states.inc.php

Code: Select all

31 => array(
                "name" => "playerTurn",
                "description" => clienttranslate('${actplayer} must play a card'),
                "descriptionmyturn" => clienttranslate('${you} must play a card'),
                "args" => "argPlayableCards",
                "type" => "activeplayer",
                "possibleactions" => array("playCard", "displayScore"),
                "transitions" => array("playCard" => 32)
        ),
All the code is here, if you're curious: https://github.com/ekelly/bga-ninetynine
User avatar
Lymon Flowers
Posts: 195
Joined: 01 April 2020, 21:14

Re: Invalid 'args' method

Post by Lymon Flowers »

Has the error occurred but when you published the new version? Or has it been reproduced consistently?

Could be some sort of race condition, like the states machine just being initialized with the new configuration but the PHP code not refreshed already.
User avatar
QuasarDuke
Posts: 18
Joined: 22 March 2020, 00:46

Re: Invalid 'args' method

Post by QuasarDuke »

It does not appear to reproduce consistently - at least, there's only one mention of it in the Unexpected Errors log. But I'm not sure if that's just because I reverted fairly quickly.
User avatar
QuasarDuke
Posts: 18
Joined: 22 March 2020, 00:46

Re: Invalid 'args' method

Post by QuasarDuke »

I sent an email to Emmanuel, and he said:
The errors stack here make me think about an issue on another game, where the player was triggering successive calls from the javascript.

In general, every ajax action call should be triggered by the user, then there is a server side process that may go into several consecutive states and send several notifications to the client. If you have some ajax calls happening inside a notification, or inside onEnteringState, or in the callback of an ajax call, then this is certainly the issue: it will send rapidfire calls to the server and result in deadlocks.

... the games are not really blocked, it's probably the same quick successive calls creating the deadlock each time. If you disable the autocalls it should probably work.
I do in fact have a single auto-call: automatically playing a forced card (when there is only one viable card to play). However, I'm struggling to figure out how this is actually the issue. To start, it's not doing anything the player couldn't do (the player can actually 'beat' the timeout to trigger playing the forced card - if they do, the timeout is cancelled). So, there still should only be one ajax call from each client side when they play a card. Secondly, it doesn't even run in spectator or replay mode. As far as I can tell, it shouldn't be sending quick successive calls creating a deadlock each time. Maybe I'm missing something?

Received playable cards:
https://github.com/ekelly/bga-ninetynin ... ne.js#L274

Handling playable cards (setting timeout):
https://github.com/ekelly/bga-ninetynin ... ne.js#L479

Clearing timeout:
https://github.com/ekelly/bga-ninetynin ... e.js#L1109

I suppose maybe it's possible that attempting to handle the playable cards in setup is what causes the problems?
https://github.com/ekelly/bga-ninetynin ... ne.js#L122
User avatar
Een
Posts: 3861
Joined: 16 June 2010, 19:52

Re: Invalid 'args' method

Post by Een »

QuasarDuke wrote: 27 January 2021, 17:25 I suppose maybe it's possible that attempting to handle the playable cards in setup is what causes the problems?
https://github.com/ekelly/bga-ninetynin ... ne.js#L122
Indeed that may be the issue, as upon load/refresh the game engine
1) Will run the setup
2) Will run onentering state for state specific code

So that's a quick succession of handlePlayableCards calls (setting a timeout with the same value... so the ajaxcalls will happen at the same time ;) )
Post Reply

Return to “Developers”