Tabletop Simulator

Tabletop Simulator

View Stats:
mannyano Jul 11, 2021 @ 10:28pm
Insert an existing card into a deck at half position
Hi,

I have got a deck of cards and a separate card. I want to shuffle the deck, and after that I want to insert the extra card into the deck at half position. I have got this so far:

function getMainDeck()
[...]
end

function isMainDeckExists()
[...]
end

function flipCheck(obj)
[...]
end

function setUpCards()
if isMainDeckExists() then
local md = getMainDeck()
flipCheck(md)
md.randomize()

local cardToInsert = getObjectFromGUID(_CARD_GUID_)
flipCheck(cardToInsert)

deckMiddleIndex = math.ceil(#md.getObjects() / 2)

-- not works on userdata of course
-- table.insert(md, deckMiddleIndex, cardToInsert)

[????]
end
end

Thanks,
Zoltan
Last edited by mannyano; Jul 11, 2021 @ 10:30pm
< >
Showing 1-3 of 3 comments
Finaryman Jul 20, 2021 @ 8:48am 

function putInside() deckobj=GET DECK TO INSERT CARD HERE cardtoadd=GET CARD HERE deckobj.shuffle() local decktable=deckobj.split(2) Wait.time( function(decktable,cardtoadd) --HERE decktable[1].putObject(cardtoadd); decktable[1].putObject(decktable[2]); end, 0.5) end
untested code... (not sure if function can accept parameters like that (HERE).)


param=nil function myShuffle() deckobj=getObjectFromGUID("703bcb") cardtoadd=getObjectFromGUID("dfc105") param={deckobj,cardtoadd} param[1].shuffle() Wait.time(mySplit,0.5) end function mySplit() local tmp=param[1].split(2) param[3]=tmp[1] param[4]=tmp[2] Wait.time(myAddOne,0.5) end function myAddOne() param[3].putObject(param[2]) Wait.time(myAddTwo,0.5) end function myAddTwo() param[3].putObject(param[4]) end function onChat(mess,plr) myShuffle() -- launched with chat message end
this worked.
Last edited by Finaryman; Jul 21, 2021 @ 3:07am
mannyano Jul 21, 2021 @ 8:44am 
Finaryman, nice solution! My solution is a bit raw, but it seems working also.

local mainDeck = getObjectFromGUID(deckguid) local card = getObjectFromGUID(cardguid) local index = math.floor(#mainDeck.getObjects() / 2) -- it can be any index if index > 1 then local decks = mainDeck.cut(index) decks[1].putObject(card) group({decks[2], decks[1]}) end
Finaryman Jul 21, 2021 @ 8:47am 
you should also test if its too high
< >
Showing 1-3 of 3 comments
Per page: 1530 50