I had this older mod that would sort cards in a deck by name. You'd place the deck in the scripting zone and click the button. The cards would all spread out and then get put into a bag and then get spit out one by one in alphabetical order. It doesn't seem to be working anymore. It spits out the cards not in alphabetical order. It was written a long time ago with an earlier version on TTS. I'm hoping maybe it just requires a few line changes. Any help would be appreciated.

Code:
function onLoad(save_state)
    button = getObjectFromGUID('1c6ade')
    zone = getObjectFromGUID('459a7b')
    output = getObjectFromGUID('c31916')
    params = {
        ['label'] = 'Sort Cards',
        ['width'] = 450,
        ['height'] = 400,
        ['click_function'] = 'alphabetize',
        ['function_owner'] = Global,
        ['position'] = {0,0.65,0},
        ['rotation'] = {0,90,0},
        ['font_size'] = 80
    }
    button.createButton(params)
end

function alphabetize()
    local deck = zone.getObjects()[1]
    local referenceTable = {}
    if deck.tag == 'Deck' then -- validate object type
        for j,k in pairs(deck.getObjects()) do
            referenceTable[j] = {}
            referenceTable[j] = {k.nickname,k.guid} -- create key,value pairs for sorting
        end
        table.sort(referenceTable,sortFunc) -- order alphabetically by nickname
        for j,k in pairs(referenceTable) do
            if deck.getQuantity() ~= 0 then
                deck.takeObject({ -- instantiate objects in order to call putObject later
                    ['guid']=k[2],
                    ['position']={math.random(-50,50),math.random(2,30),math.random(-50,50)},
                    ['callback']='outputCard',
                    ['callback_owner']=Global
                })
            else
                Timer.create({
                    ['identifier'] = 'endOfSort',
                    ['function_name']='endOfSort',
                    ['function_owner']=Global,
                    ['delay']=1.5
                })
            end
        end
    end
end

function outputCard(card)
    output.putObject(card) -- places cards into the bag
end

function endOfSort()
    zone.getObjects()[1].setPosition({output.getPosition()[1],output.getPosition()[2]+3,output.getPosition()[3]})
    for i=1,output.getQuantity()+1,1 do
        Timer.Create({ -- delay the drawing of each new card from the alphabetixed bag to allow physics room to work
            ['identifier'] = 'nextCard'..i,
            ['function_name']='nextCard',
            ['function_owner']=Global,
            ['delay']=i/2
        })
    end
end

function nextCard()
    output.takeObject({ -- place the card on the table
        ['position']={0,2,0},
        ['rotation']={0,180,0}
    })
end

function sortFunc(a,b)
    return a[1]>b[1]
end
Here's a .json file if you wan't to see it in action.

https://www.dropbox.com/s/v16bou7h6rkjyj5/TS_Save_100.json?dl=0