Results 1 to 4 of 4

Thread: Calling Player[color].getHandObjects() throws error while Player groups cards.

  1. #1

    Unhappy Calling Player[color].getHandObjects() throws error while Player groups cards.

    Hi there!
    I just wanted to report a minor but slightly annoying bug, occurring in the following scenario:

    I was calling a function from within update(), which uses Player[color].getHandObjects() to count the number of cards in a Player's hand, and then hand out cards to the player accordingly.
    However, as I noticed, when the Player that is currently being checked up on is currently in the process of grouping up the cards (by for example marking multiple and then pressing "G"), the game throws the small error:
    "Error in Global Script update function:"

    However, no code seems to break because of this, so it's not major. The error message is a bit inconvenient though.

    Here's my code:
    --[[ Lua code. See documentation: --]]
    --[[ The OnLoad function. This is called after everything in the game save finishes loading.
    Most of your script code goes here. --]]
    deckGUID = 968572;
    deck = nil;
    function onload()
        --[[ print('Onload!') --]]
        deck = getObjectFromGUID(deckGUID);
    lastDealt = 0;
    function givePlayerCards(color, number)
        pHand = Player[color].getHandObjects();  -- This seems to throw an error while grouping together cards in a player's hand
        if(pHand == nil) then return; end
        pHand = #pHand;
        if(pHand >= number) then return; end
        if(lastDealt >= os.clock()) then return; end
        print("Dealing new cards!");    
        lastDealt = os.clock() + 1;    
        if(not (deck == nil)) then
            deck.dealToColor(number - pHand, color); 
            print("Dealt new cards!");
    --[[ The Update function. This is called once per frame. --]]
    function update ()
        -- print('Update loop!');
        givePlayerCards("White", 3);
    function onObjectDropped(pC, obj )
    	    obj.highlightOn({1, 0, 0}, 1);

  2. #2
    Join Date
    May 2016
    Does it also throw the error if the hand zone does not contain any objects? It may be that in the moment of grouping the hand zone is not detecting them because it temporally loses its "grip" on them?

    Good bug report either way, I'm just wondering.

  3. #3
    I've tested, and no.
    It's only when you group objects currently inside the hand zone(s).

    Why exactly this does this is a mystery to me though - I am not actually using any data of the returned table, merely calling 'getHandObjects" throws the error - so it must be something within the backend updating what cards exist in the hand at different times, leading to null pointers?

    But even that doesn't quite get it right, because the error occurs multiple times when just grouping once ... So maybe the newly generated stack actually counts as a hand object for a moment, causing one error, before falling out and causing a second, somehow identical one...

    Glad to see it was seen though!

  4. #4
    Just so you're aware, you don't need the semi-colon to indicate a new line in Lua. Everywhere you've placed a semi-colon in your script, there's no need for it to be there.
    You can actually run Lua code all on one line if you wanted (though this makes it kind of unreadable).

    Maybe try looping through the hand objects and checking their tags? If a Deck shows up rather than a card, then print something.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts