Add random dialogue to "used"

I have a modular script that stores possible dialogs in the form of

local module = {
{“...”},
{“...”, “...”},
} return module

The dialogs are played randomly by a local script, and I need them not to repeat

I tried to add them to an array inside this local script, but it either doesn’t work or it cuts the dialog {“…”, “…”} to the first part without showing the second part

Help pls

1 Like

hmmm try using oop I will give a example

local module = {}
module.__index = module

function module.new()
    local self = setmetatable({}, module)
    self.texts = {}
    self.filteredTexts = {}
    return self
end

function module:FilterTexts(conditionText)
    if self.texts[conditionText] then
        table.insert(self.filteredTexts, conditionText)
        return conditionText
    else
        local keys = {}
        for key in pairs(self.texts) do
            table.insert(keys, key)
        end
        if #keys > 0 then
            local randomText = keys[math.random(#keys)]
            table.insert(self.filteredTexts, randomText)
            return randomText
        end
    end
end

return module

Im not sure if this is really what you want but this is what I would use

1 Like

alternatively just:

local dialogs = table.clone(require(dialogmodule))
Random.new():Shuffle(dialogs)

now the dialogs are randomly ordered and you can just loop trough them or get the first one and then remove the first index

1 Like

:sob: yeah also that can be used idk why I decided to write those all

it looks like a great solution, but because of a massive skill issue, after changing the code for it, everything stopped working for me (the code converts tables to string, but after the changes it doesn’t see tables, only nil)

tomorrow I will try further (now I can’t even show what code I got)