While I had fun testing several oop method on roblox I made his
type Dialog = {Npc: Model, Npc_Name: string, Id_Dialog: string, Dialog: string, Active: boolean}
local dialogs = {
{
Npc = workspace["The Welcomer"],
Npc_Name = workspace["The Welcomer"].Name,
Id_Dialog = "Id_wlc",
Dialog = "Hello newbody how are you",
Active = true
},
}
local module = {}
module.__index = module
function module.new(dialog: Dialog)
local self = setmetatable({}, module)
self.Dialog = dialog
return self
end
function module.getDialogById(id: string): Dialog
for _, v: Dialog in dialogs do
if v.Id_Dialog == id and v.Active then
return v, true
else
return "Failed to get dialog !", false
end
end
end
function module.getDialogByNpcName(name: string): Dialog
for _, v: Dialog in dialogs do
if v.Npc_Name == name and v.Active then
return v, true
else
return "Failed to get dialog !", false
end
end
end
function module.SetDialog(self: SelfDialog)
print(self.Dialog)
end
export type SelfDialog = typeof(module.new(...))
return module