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
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
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)