Results 1 to 3 of 3

Thread: Finding Descriptions of all the cards in a Deck

  1. #1

    Finding Descriptions of all the cards in a Deck

    Hi all. I'm a new-ish modder who has been learning Lua over the last week or so, but I've hit a syntax wall on one of the last operations I need to get my first mod up and running the way I want.


    I'd like to have a function that can go through a deck created after the game starts and check what the Name or Description of each card in the deck is for scoring purposes.

    When I look through the API documentation it says this about using getObjects() on a deck:

    Capture.JPG


    But for the life of me I cannot figure out how to interact with the getObjects() data from the deck in any meaningful way, and there don't seem to be any further examples for it.

    My basic test code right now looks like:

    function testFunc()
    local workZone = getObjectFromGUID('589584') --a scripting zone over the singular deck I'm testing with
    workDeck = workZone.getObjects()
    for k,v in pairs(workDeck) do
    print(v.getDescription())
    end
    end

    I've tried a few permutations of this, calling for things like 'workCards[1]' or 'v.getDescription' etc, but I always seem to get either an error, "table: [hexcode]", or "function: [hexcode]".

    What syntax do I have to use to get at the juicy bits of the sub-tables the API shows? I have to use a scripting zone to interact with the deck since it'll be a user-created one, not one that exists in the actual initial save, so we won't know the GUID ahead of time.

    Thanks for any responses in advance.

  2. #2
    Join Date
    Feb 2017
    Posts
    178
    You need a nested loop here. If you're grabbing all the objects in a zone, you then have that object, if the object is a deck, then you can loop through the information in the deck.
    OR, you can grab the deck directly using the GUID if you know the GUID of the deck.

    local workZone = getObjectFromGUID('589584')
    for _,obj in ipairs(workZone.getObjects()) do
    if (obj.tag == 'deck') then --not sure of actual tag of a deck, just a guess
    for k,card in ipairs(obj.getObjects())
    log(card.getDescription())
    end
    end
    end

  3. #3
    Quote Originally Posted by FoaS View Post
    You need a nested loop here. If you're grabbing all the objects in a zone, you then have that object, if the object is a deck, then you can loop through the information in the deck.
    OR, you can grab the deck directly using the GUID if you know the GUID of the deck.

    local workZone = getObjectFromGUID('589584')
    for _,obj in ipairs(workZone.getObjects()) do
    if (obj.tag == 'deck') then --not sure of actual tag of a deck, just a guess
    for k,card in ipairs(obj.getObjects())
    log(card.getDescription())
    end
    end
    end
    Yes! That got it! I had tried something like that before, but I think I must have got it messed up as it also looks like it wants "card.description" instead of "getDescription". I must have abandoned that tack too soon. Thanks!

    Here's the relevant part of the code that worked for anyone else that runs into this:

    Code:
     local workZone = getObjectFromGUID('589584')
    for _,obj in ipairs(workZone.getObjects()) do
    if (obj.tag == 'Deck') then
    for k,card in ipairs(obj.getObjects()) do
    print(card.description)
    end
    end
    end
    EDIT: After actually working with the code it seems like any object that's inside a container like a deck or bag wants you to call on its information with "[object].description", while any singular object wants the equivalent "[object].getDescription()" and so on. "[object].getName()" and "[object].getGUID()" become "[object].name" and "[object].guid" etc
    Last edited by SmallFry; 03-13-2019 at 11:34 AM. Reason: further clarity to findings

Similar Threads

  1. Finding a specific card in a deck
    By DonnyT in forum Scripting
    Replies: 7
    Last Post: 03-27-2018, 03:48 PM
  2. Replies: 2
    Last Post: 12-05-2017, 11:26 AM
  3. I need help finding the Saved Objects folder on my Mac
    By COMBanzai in forum General Discussion
    Replies: 3
    Last Post: 06-26-2017, 01:24 PM
  4. Finding broken objects
    By Baryonyx in forum Suggestions
    Replies: 4
    Last Post: 05-23-2017, 11:21 AM
  5. Replies: 3
    Last Post: 06-02-2015, 07:57 AM

Posting Permissions

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