Tabletop Simulator

Tabletop Simulator

View Stats:
Kahn May 20, 2020 @ 12:42pm
Retrieve a specific card from a deck
Hi all,
I am trying to get a script for grabbing a specific card from a deck. I have searched all the topics and gone on the help website and it is just not making sense to me. I have this code for when each player grabs a faction card, it grabs its matching card from the deck and brings both back to close to their hand. When the card is not in the deck, it works obviously , but not when its in the deck. I have read the items about it doesn't exist when it's in the deck and everything.

if color=='Red' then getObjectFromGUID("e6a849").setPositionSmooth({-29.50,2,-33.00}) end if color=='Red' then Wait.frames(function() getObjectFromGUID("99cb24").setPositionSmooth({29.50,3,33.00}) end, 60) end -- this is the card

the guid for the deck is "271e4d".

If anyone has a script that does exactly this, and willing to share, it would be greatly appreciated,
thank you,
< >
Showing 1-15 of 15 comments
wizcreations May 20, 2020 @ 8:22pm 
I'm still learning to code this myself, so someone else may be able to give a better answer. I believe the reason it doesn't work for you is cards in decks do not have their own GUIDs, but you can assign a GUID to them if they have a name. And maybe another way too that I don't know about. I haven't played with this tool, but it might work better than what I describe below:
https://steamcommunity.com/sharedfiles/filedetails/?id=1180142950

If you name every card in your deck, then you'll be able to identify cards by name and take them that way. The following function will search for a card by name in your deck, then if found move it smoothly to position {29.5, 3, 33}. If the card is not found in the deck, it broadcasts a message to all saying "Card not found." You can set the activation of this function to trigger when a faction card leaves a script area, or whatever other method you want to use.

function take_card() local found=false local deckDeck = getObjectFromGUID("271e4d") local deckContents = deckDeck.getObjects() local CardGuid = {} for _, object in ipairs(deckContents) do if object.name == "NameOfCardHere" then CardGuid=object.guid local params = { position = {29.5, 3 ,33} , guid = CardGuid } deckDeck.takeObject(params) found = true break end end if found==false then broadcastToAll("Card not found") end end
Last edited by wizcreations; May 20, 2020 @ 9:10pm
Bone White May 20, 2020 @ 11:32pm 
Long story short, don't rely on guids for objects. Assign them your own id in their gm notes, then find them by that. TTS won't "correct" this value.

For more information, hit up #scripting in the official TTS discord.
Kahn May 21, 2020 @ 4:04pm 
Thank you wizcreations, Code seems to be working.

Some of my confusion was I saw many people who named cards, then put them into a deck, it would erase their names, so I was confused on how that would work.

I will also note the code didnt work at first when I put it in and named the card. Even after naming all cards in the deck it didnt work, I had to remove all cards from the deck, and re-stack it, then it started working. Not sure why. It was pulling random cards until i did that. Weird,

but again, thank you!
Kahn May 23, 2020 @ 4:12pm 
Just wanted to update. After doing some more code, this stopped working for me. After lots of trouble shooting, I think i figured out what was messing it up.
I had a code to randomize this deck after the load, but before the cards are drawn. Once i removed this, and have it randomize afterwards, it started to work as normal again.
wizcreations May 24, 2020 @ 6:26am 
I have no clue why that issue would occur. In the program I wrote, the deck has an onLoad function to immediately shuffle. Either way, glad to know it is still working for you.
Kahn May 24, 2020 @ 10:28am 
Yeah, I dont know either. I have it on 2 different decks, one with 8 cards, one with 35 cards. The 8 card decks worked fine, but the larger deck didnt. Only thing I noticed different was the larger deck shuffling before hand. Once I removed that, it started working again. Coding sure can be funky some times.
Kahn May 24, 2020 @ 4:32pm 
I think i spoke too soon...I am still having issues with the larger deck. I have 16 different cards from that deck that have been scripted when different buttons are pressed. 90% of them work, but there are 2 or 3 that dont. they pull random cards until the correct one it drawn. I have copied a working code and pasted it over top but still doesnt fix it...

Any chance you could look at my code and see what might be causing this?
thank you.
wizcreations May 24, 2020 @ 7:43pm 
Sure. I'll pretend to know what I'm doing and help troubleshoot. Maybe we'll both learn something new! Is it for the Warpgate workshop item or something else you're working on?
Kahn May 25, 2020 @ 4:17am 
I hope, Always up to learning something new. Yes, its for the Warpgate workshop, once this is figured out, I will be able to update with a setup script. I will send you a Private Message then post the finding here incase someone needs this in the future
Siddarth Vader Feb 19, 2021 @ 3:16pm 
Originally posted by Kahn:
... then post the finding here incase someone needs this in the future

^-^''

Did you find the answers you (and I) are looking for?
Kahn Apr 6, 2021 @ 3:55pm 
I have not. Havn't been on here since I started back to work after the Covid lockdown.
MessiahofMelons Jul 23, 2021 @ 7:30am 
Hey so, I've recently been learning tabletop scripting and I was using your code and am able to draw the exact card I want out of a deck of 100 every time. I pulled 10 cards with no issue if an issue shows up in the future I will post again. Note I used the text tool to input the name of the card I want to draw. But I imagine you could get the name from anywhere. I don't know if this is the same issue you are having but at the very least the below code works for me

function DrawSpecificCard() local found=false local DeckToDrawFrom= getObjectFromGUID("DeckGuid") local deckContents = DeckToDrawFrom.getObjects() local InputText = getObjectFromGUID("guid of text tool") local CardName= InputText.getValue() for _, object in ipairs(deckContents) do if object.name == CardNamethen local params = { position = {Position to put card} , index = object.index } DeckToDrawFrom.takeObject(params) print("Found Card") found = true break end end if found==false then broadcastToAll("Card not found") end end
Finaryman Jul 24, 2021 @ 2:33am 
why not use getData() to get CardID. it is always unique if card is unique.
function getSpecIndex(cardid) local Deck=getObjectFromGUID("ff4305") local cont=Deck.getData()["ContainedObjects"] for i, obj in ipairs(cont) do if obj["CardID"] == cardid then return i - 1 end end end
this function returns index of cardid card you provided.

then
function takeCardID(cardid,color) local Deck=getObjectFromGUID("ff4305") local cardindex=getSpecIndex(cardid) if cardindex ~= nil then return Deck.takeObject({index=cardindex,position=getMyPlace(color)}) end end

and make getMyPlace function to get position where you want place the card.
function getMyPlace(color) --GET POSITION HERE return position end
Last edited by Finaryman; Jul 24, 2021 @ 4:10am
MessiahofMelons Jul 24, 2021 @ 5:03am 
Originally posted by Finaryman:
why not use getData() to get CardID. it is always unique if card is unique.
function getSpecIndex(cardid) local Deck=getObjectFromGUID("ff4305") local cont=Deck.getData()["ContainedObjects"] for i, obj in ipairs(cont) do if obj["CardID"] == cardid then return i - 1 end end end
this function returns index of cardid card you provided.

then
function takeCardID(cardid,color) local Deck=getObjectFromGUID("ff4305") local cardindex=getSpecIndex(cardid) if cardindex ~= nil then return Deck.takeObject({index=cardindex,position=getMyPlace(color)}) end end

and make getMyPlace function to get position where you want place the card.
function getMyPlace(color) --GET POSITION HERE return position end
Can't speak for others but my deck is supposed to remain secret and unshuffled. So I don't know any of the ids. But they were all named 1-100 so I had names to reference easily to get the index
Finaryman Jul 24, 2021 @ 5:08am 
script runs hidden. it doesn't tell anyone, it is possible to make script match cardid with other card. my version removes need for name cards.

even if you found out indexes when finding out cardids, you could shuffle afterwards found out cardids, then you would only know what cards there are but not where.
Last edited by Finaryman; Jul 24, 2021 @ 12:58pm
< >
Showing 1-15 of 15 comments
Per page: 1530 50

Date Posted: May 20, 2020 @ 12:42pm
Posts: 15