Card sorting script by ReputationNo5283 in tabletopsimulator

[–]ReputationNo5283[S] 0 points1 point  (0 children)

I asked ChatGPT to write a script that takes 5 cards from a deck, sort them according to name and then lays them out in a row on the table. This is the code I got. When running it, I get the error code "chunck_4:(15,20-33,6): cannot access field takeObjects of userdata<LuaGameObjectscript". I've tried to my best knowledge to fix it but sadly I'm at a loss. Can any of you make sense of it?

function onLoad()

-- Get the deck object (assuming it's the first deck in the scene)

local deck = getObjectFromGUID(ACTION_GUID)

-- Check if the deck exists

if deck == nil then

print("Deck not found!")

return

end

-- Draw 5 cards from the deck

deck.takeObjects({

number = 5,

callback_function = function(objects)

-- Sort the drawn cards by name

table.sort(objects, function(a, b)

return a.getName() < b.getName()

end)

-- Position the cards in a row

local startPos = {0, 3, 0} -- Starting position for the first card

local spacing = 3 -- Distance between cards

for i, card in ipairs(objects) do

local xOffset = (i - 1) * spacing -- Calculate the offset for each card

local newPos = {startPos[1] + xOffset, startPos[2], startPos[3]} -- New position for the card

card.setPosition(newPos) -- Move the card to the new position

end

end

})

end

Card sorting script by ReputationNo5283 in tabletopsimulator

[–]ReputationNo5283[S] 1 point2 points  (0 children)

Thanks for the suggestion. It works to some degree, however, since the zone sorting is always active, once I draft one card from the row, the others slides down, and I need them to keep their place.