Bulthax
Bulthax

Reputation: 9

LUA Scripting in Tabletop Simulator

Not sure if this is the place to post this kind of question, I think someone needs to be familiar with the TableTop Simulator game to help, but I figured I'd try. I am trying to create a script that uses Script Boxes to check what the description of a card is in the location, and once a new card is drawn to one of the 4 Script Boxes, if that description equals 'Fast', the card gets moved to the first Box and all the previous cards move over 1 box. However every time the 4th card is Fast it moves reads the 4th card twice and moves it to the first Box and then back to the 4th box, instead of moving the 3rd card to the 4th box. I can't figure out why it's getting the 4th card twice.

fc = the amount of cards in place + the one being added

d = nil
fz = 0

function onLoad()
    DeckZone = {getObjectFromGUID('2d5588'), getObjectFromGUID('bf2a55'), getObjectFromGUID('5bdb70'), getObjectFromGUID('d01463')}  -- guid of script boxes with decks in them
    CombatZone = {getObjectFromGUID('2d2792'), getObjectFromGUID('74aafc'), getObjectFromGUID('68ebc9'), getObjectFromGUID('30818f')} -- the guids of the boxes
    Combat = {CombatZone[1].getPosition(),CombatZone[2].getPosition(),CombatZone[3].getPosition(),CombatZone[4].getPosition()} -- the Positions of the boxes

-- Buttons correlating to the decks being pulled from --
        DeckZone[3].createButton({
            click_function="click_drawCombat", function_owner=self, alignment=3,
            position={0, -0.45, 0}, height=450, width=450, font_size=1000, color = {1,1,1,1}, tooltip = "Click to Draw Combat Card."
        })
        DeckZone[4].createButton({
            click_function="click_drawCombat", function_owner=self, alignment=3,
            position={0, -0.45, 0}, height=450, width=450, font_size=1000, color = {1,1,1,1}, tooltip = "Click to Draw Combat Card."
        })
end

function click_drawCombat(obj)
    local deck = obj.getGUID()
    if deck == "5bdb70" then
        d = 3
    elseif deck == "d01463" then
        d = 4
    end
    findDeck()
    if #objects > 0 then
        if type == 'footsoldier' then
            if fz < 4 then
                fz = fz + 1
                table.insert(FSDeckZoneSaved, obj)
                local faceup = {}
                faceup.position = Combat[fz]
                faceup.flip = true
                local pos = Combat[fz]
                for _, obj in ipairs(objects) do
                    globalDeck.takeObject(faceup)
                    Wait.time(function() fastCard(fz) end, 0.3, 1)
                end
            end
        end
    end
end

function findDeck()
    globalDeck = nil
    objects = DeckZone[d].getObjects()
    for i, deck in ipairs(objects) do
        globalDeck = getObjectFromGUID(deck.getGUID())
    end
end

function findCombat()
    globalDeck = nil
    objects = CombatZone[cz].getObjects()
    for i, deck in ipairs(objects) do
        globalDeck = getObjectFromGUID(deck.getGUID())
    end
end

--part that not's working below--

function fastCard(fc)
    cz = fc
    fC = fc
    findCombat()
    fast = globalDeck.getDescription()
    fastCardTest(fc)
end

function fastCardTest(fc)
    if fast ~= 'Fast' or fc == 1 or fc == 5 then
        Wait.time(combatDeckButtons, 1.5, 1)
    end
    if fast == 'Fast' and fc > 1 and fc ~= 5 then
        for t=1,cz do
            if cz == fc then
                findCombat()
                guid = globalDeck.getGUID()
                pos = Combat[1]
                globalDeck.setPositionSmooth(pos, false, false)
            end
            if cz ~= fc then
                findCombat()
                pos = Combat[cz+1]
                globalDeck.setPositionSmooth(pos, false, false)
            end
            cz = cz - 1
        end
        Wait.time(combatDeckButtons, 1.5, 1)
    end
end

Upvotes: 1

Views: 2665

Answers (0)

Related Questions