Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can you use return to return a tuple?

Asked by
wrenzh 65
10 years ago

Basically the above question.

I'm trying to use return to return both a boolean value and a string. I am making a chat filter for my chat GUI, and I am using a function that checks whether a chat is in compliance with the filter and then returns whether that chat was in compliance or not and what the reason was (if it was not compliant).

The function in question is below (it is a global function because I plan to use it in other scripts).

_G.CheckFilter = function(chat)
    lower = chat:lower()
    -- the chat filter is here. It contains some words that I am not sure are in compliance with guidelines, so it has been removed
} 

    for key, value in pairs(filtered) do
        if lower:find(key) then
            return true, value
        end
    end
end

And then it is called in the following code:

debounce = false

script.Parent.Parent.Parent.Chatted:connect(function(msg)
    lower = msg:lower()
    if player.Name == "Kaamchor" or player.Name == "Devinoski" or player.Name == "darkyellow56" then
        if string.lower(msg:sub(1, 6)) == "system" then
            _G.Chat(msg:sub(8), "SYSTEM")
        end
    end
    if debounce == false and string.lower(msg:sub(1, 6)) ~= "system" then
        debounce = true
        local filt, reason = _G.CheckFilter(msg)
        if filt then
            _G.Chat("This message by " .. player.Name .. " was filtered because of: " .. reason .. ".", "SYSTEM")
            wait(3)
            debounce = false
        else
            _G.Chat(msg, player.Name)
            wait(1)
            debounce = false
        end
    end
end)

Answer this question