Hello! I am trying to create a module script that:
- finds 1 or more substring(s) from a given string
- replaces the substring(s) with a different substring for each one
- returns the modified string, so I can use it on other scripts.
However, I am a bit stuck on it, so can anyone tell me how to fix it?
Here is the code:
local module = {
["Dictionary"] = {
["Cat"] = {
"Ice Cream",
"Cookie",
"Cake"
["Dog"] = {
"Pizza",
"Hamburger",
"Taco"
}
}
}
function lower(str)
return str:lower()
end
function random(min, max)
return math.random(min, max)
end
function module:ReplaceWords(givenString)
local loweredString = lower(givenString)
if loweredString:find("cat") then
local cat = module.Dictionary.Cat
local newString1 = string.gsub(loweredString, "cat", cat[random(1, #cat)
if loweredString:find("dog") then
local dog = module.Dictionary.Dog
local newString2 = string.gsub(loweredString, "dog", dog[random(1, #dog)
return newString2
else
return newString1
end
else
return loweredString
end
end
return module
please help