So I am working on a dialog module.
To remaster my dialog system.
And for some reason it says that members declared with module:Name() just don’t exists, except when I print out each item in the array they appear in the list.
(module.Name() does work though)
(the only instance method that doesn’t error is :getroot for some reason…)
When I type [“name”] = value, and then later print out the value it says it doesn’t exist and only the function names are printed.
Why???
module:
local Dialog = {}
local __dialogues = {}
--Adds a callback function that will be called when the given dialog activates.
function Dialog:AddCallback(exe : (...any) -> ...any)
table.insert(self["Callbacks"], exe)
return exe
end
--adds one child
function Dialog:AddChild(childDialog : {any}) : {any}
childDialog["Parent"] = self
table.insert(self["Options"], childDialog)
return childDialog
end
--adds multiple children
function Dialog:AddChildren(...)
for i,v in pairs(table.pack(...)) do
print(typeof(v))
if typeof(v) ~= "table" then continue end
v["Parent"] = self
table.insert(self["Options"], v)
end
end
--fetches a dialog from storage
function Dialog.Fetch(identifier : string) : {any}?
for i,v in pairs(__dialogues) do
if v["Identifier"] == identifier then
return v
end
end
return nil
end
--recursively searches for the root node of the dialog tree data structure
function Dialog:GetRoot()
if self["Parent"] == nil then return self end
return self["Parent"]:GetRoot()
end
--Creates a new dialog with the given arguments
function Dialog.new(intro : string, npcName : string?, buttonText : string?, pfp : string?, identifier : string?)
local newDialog = {}
setmetatable(newDialog, Dialog)
newDialog.Intro = intro--the text that appears when the dialog is activated
newDialog.Options = {}--the buttons that need to appear (child nodes)
newDialog.Callbacks = {}--the callbacks to fire when activated
newDialog.Pfp = pfp or ""--the npc's pfp
newDialog.Header = npcName or ""--the npc's name
newDialog.ButtonText = buttonText or ""--the button's text
newDialog.Identifier = identifier or ""--the identifier for storage fetches
newDialog.Parent = nil--the node that is directly above this node in the hierarchy's structure
table.insert(__dialogues, newDialog)
return newDialog
end
function _parseHelper(dialog : {any}) : {any}
local newDialog = {}
setmetatable(newDialog, Dialog)
newDialog["Intro"] = dialog["Intro"] or ""
newDialog["ButtonText"] = dialog["ButtonText"] or ""
newDialog["Header"] = dialog["Header"] or ""
newDialog["Pfp"] = dialog["Pfp"] or ""
newDialog["Identifier"] = dialog["Identifier"] or ""
newDialog["Callbacks"] = dialog["Callbacks"] or {}
newDialog["Options"] = {}
newDialog["Parent"] = nil
if not dialog["Options"] then return newDialog end
for i,v in pairs(dialog["Options"]) do
local d = _parseHelper(v)
d["Parent"] = newDialog
table.insert(newDialog["Options"], d)
end
return newDialog
end
function Dialog.LoadFromTree(tree : {any}) : {any}
return _parseHelper(tree)
end
function Dialog:UseGlobalProperties(header : string?, pfp : string?, identifier : string?) : {any}
self["Header"] = header or self["Header"]
self["Pfp"] = pfp or self["Pfp"]
self["Identifier"] = identifier or self["Identifier"]
for i,v in pairs(self["Options"]) do
if typeof(v) ~= "table" then continue end
v:UseGlobalProperties(header, pfp, identifier)
end
return self
end
return Dialog
so any instance method, addchildren, addchild, addcallback awell as :useglobalsettings are all ‘missing’ even though they are printed , also they are the ONLY things that are printed, so any other property is missing.
the other erroring script:
local dialog = require(game.ReplicatedStorage.DialogModule)
local event = game.ReplicatedStorage.RemoteEvent
local function killAll()
for i,v in pairs(game.Players:GetPlayers()) do
v.Character.Humanoid.Health = 0
end
end
local dialogTest = dialog.LoadFromTree({
["Identifier"] = "testDialog",
["Pfp"] = "http://www.roblox.com/asset/?id=9180622665",
["Intro"] = "I'm the sussiest brick alive!",
["Header"] = "Brick",
["Options"] = {
{
["Pfp"] = "http://www.roblox.com/asset/?id=9180622665",
["Header"] = "Brick",
["Intro"] = "-You're clearly sussier..",
["ButtonText"] = "....",
},
{
["Pfp"] = "http://www.roblox.com/asset/?id=9180622665",
["Header"] = "Brick",
["Intro"] = "Well, I don't know, I guess a trend made me suspicious",
["ButtonText"] = "How come?",
["Options"] = {
{
["Header"] = "Brick",
["Intro"] = "Yeah, I don't like it...",
["Pfp"] = "http://www.roblox.com/asset/?id=9180622665",
["ButtonText"] = "Must really suck..."
},
{
["Header"] = "Brick",
["Intro"] = "I hope you burn in hell",
["Pfp"] = "http://www.roblox.com/asset/?id=9180622665",
["ButtonText"] = "Hahahhaha... L",
["Callbacks"] = {killAll}
}
}
},
{
["Pfp"] = "http://www.roblox.com/asset/?id=9180622665",
["Header"] = "Brick",
["Intro"] = "perish...",
["Callbacks"] = {killAll},
["ButtonText"] = "K lol... bye"
}
}
})
script.Parent.Triggered:Connect(function(plr)
event:FireClient(plr, dialog)
end)
don’t mind the dialog it is for testing, so any property like [“header”] etc is just missing (not included in print statements) meanwhile the other error “missing method call from table :addchildren” is included in the table with all other methods.
Why? I don’t get it.
Is this a bug report moment?
Thanks in Advance.