Results 1 to 8 of 8

Thread: Finding a specific card in a deck

  1. #1

    Finding a specific card in a deck

    I'm trying to find specific cards in a deck that correspond to some die. Basically, the die are rolled, then the cards are removed from the deck into another pile based on the die rolled. What's the best way to do that?

  2. #2
    You just loop through cards in the deck and do your check. Use takeObject to get them out to some position.
    Code:
    for k,card in ipairs(deck.getObjects()) do
        -- e.g. take one with 'Die result X' name, X is the die number
        if card.nickname == ('Die result ' .. die.getValue()) then
            local targetPos, targetRot = anotherPile.getPosition(), anotherPile.getRotation()
            targetPos.y = targetPos.y + 2
            deck.takeObject({index = card.index, position = targetPos, rotation = targetRot})
        end
    end

  3. #3
    Quote Originally Posted by dzikakulka View Post
    You just loop through cards in the deck and do your check. Use takeObject to get them out to some position.
    Code:
    for k,card in ipairs(deck.getObjects()) do
        -- e.g. take one with 'Die result X' name, X is the die number
        if card.nickname == ('Die result ' .. die.getValue()) then
            local targetPos, targetRot = anotherPile.getPosition(), anotherPile.getRotation()
            targetPos.y = targetPos.y + 2
            deck.takeObject({index = card.index, position = targetPos, rotation = targetRot})
        end
    end
    Wow tnx a bunch. How does the ".." work? Also, would I have to give a nickname to each card?

  4. #4
    Quote Originally Posted by DonnyT View Post
    Wow tnx a bunch. How does the ".." work? Also, would I have to give a nickname to each card?

    this is how LUA appends strings and variables.

    So...

    str = 'This is a string'
    strA = 'Added to the string'

    print(str .. stA)
    >This is a stringAdded to the string)

    print('Demo: ' .. str .. ' : ' .. stA .. '.')
    >Demo: This is a string : Added to the string.
    Last edited by Tragic; 03-20-2018 at 02:08 AM.
    My Boardgame uTube chan - Tragic's Table Top
    BGG Guild of BoardGame uTubers - Tube Tables

  5. #5
    Nickname is whatever you put in the "Name" field when you take the card out of the deck and right click it. "Description" is the box just under it.

  6. #6
    So far, I have this but am getting some errors. "Object reference not set to an instance of an object."
    The function is supposed to get the rotation value of 6 die and find a card in a deck that matches that die and put it in a new pile, so the new pile should have 6 cards, but it seems to be random as it is now.



    function forecast() --creates the forecast deck
    fcpos = {31.39, 1.03, 8.79}
    local rolleddie = {}
    local fcfound = nil
    local fcdeck = nil
    local objectsInZone = fcczone.getObjects()
    for k, v in ipairs(dice_GUID) do
    table.insert(rolleddie,getObjectFromGUID(v).getRot ationValue())
    end
    for i, object in ipairs(objectsInZone) do --find deck in zone
    if object.tag == "Deck" then
    fcfound = object.getObjects()
    --local fcdeck_GUID = object.getGUID()
    fcdeck = getObjectFromGUID(object.getGUID())
    end
    end
    for j, w in ipairs(rolleddie) do --for each die
    for h, card in ipairs(fcfound) do --for each card in the found deck
    if card.nickname == w then
    fcdeck.takeObject({
    index = card.index,
    position = fcpos
    })
    end
    end
    end
    end

  7. #7
    Join Date
    May 2016
    Posts
    1,072
    fcdeck = getObjectFromGUID(object.getGUID()) Can just be fcdeck=object I do believe.

    As for the error you got, you got it because you attempted to reference an object which does not exist. Try to print before each use of an object you have, ie. print(fcdeck) before doing fcdeck.takeObject.

    Additionally, when you take a card by its index, all other higher indexes shift down automatically. This means if you want index 2 and index 3, if you take index 2, now the card that used to be index 3 is shifted down to index 2. At least if memory serves me it does. I usually track the card GUIDs instead. I think I put an example of pulling a card by one of its properties here http://steamcommunity.com/sharedfile.../?id=879494019

    If you DO take cards by GUID, be aware that a custom deck assigns all of its cards the same GUID. I made this to split out all the cards at once, forcing them to be assigned new GUIDs, then you can save the table/deck now that all the cards have unique guids. http://steamcommunity.com/sharedfile...?id=1180142950

    If you are still having issues, let me know and I'll work up a demo script

  8. #8
    Much appreciated!

Similar Threads

  1. Finding a card by GUID anywhere in the game
    By Bone White in forum Scripting
    Replies: 2
    Last Post: 12-20-2017, 01:26 PM
  2. Card deck subset of regular deck
    By Wolfman in forum General Discussion
    Replies: 2
    Last Post: 07-09-2017, 09:42 AM
  3. Replies: 2
    Last Post: 07-07-2016, 05:15 PM
  4. Draw Specific Card from Deck
    By Eskander in forum Scripting
    Replies: 10
    Last Post: 05-04-2016, 04:17 PM
  5. Replies: 1
    Last Post: 04-27-2015, 04:36 PM

Posting Permissions

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