after taking a look at the pastebin, was there any reason why the empty dialogues were being kept there?
you don’t need empty keys if they’re empty, if they’re all the same, then when any script would try to get them you could just treat them as
if dialogueValue==nil then dialogueValue="" end
that is, if you even need the empty keys, which you probably don’t, so they not existing at all would be even better.
i understand that it’s all empty ATM, but it honestly shouldn’t exist if it doesn’t exist yet.
Here’s the i’d do it, it’s very efficient, clean, and best of all, modular and reusable, you don’t need to nest things, just reference them by their ID.
i wrote lots of different usages and scenarios in the --comments, if you can understand the general idea you’ll be good to go.
local DialogueTable={
Character_1={ -- this is entirely optional, just for organizing things for different characters
-- you'd be better off without it if you want different characters to use the same dialogue
-- but it can even be by a script on game start, i do with lots of tables
-- just loop through the primary "unwanted" tables and place all their contents inside the main one you're looping through, and then delete the now empty 'Character_1' entry
-- as long as you don't create two values in two different 'Character tables' with the same ID, you'll be good, so it's always good to have the "replacing" function check if the key is duplicate and warn you so you can fix it
DIA_A0={
Texts={ "This is the main text" },
Choices={ "DIA_A1","DIA_A2", },
},
DIA_A1={
Texts={ "Second Choice", },
Choices={}, --if #lenght of Choices table is 0, you can make it automatically treat it as and 'End Dialogue' without creating an specific dialogue for ending it
},
DIA_A2={
Texts={ "hey, this is the first text?", "this is the second text", "and third, lol", }, --the order of texts is the order in which they're placed inside the ARRAY
--but if you make it a dictionary (giving it a key, instead of just throwing it inside a table) then it's order is random, so it only works like this
Choices={ "DIA_A2a","DIA_A2b","DIA_A2c", },
--same principle of order, here you'd place the ID of the new dialogue which would be inside Character_1's table, no need to nest things
-- +they can (and should) be reused by other dialogues
},
DIA_A2a={
Texts={"generic text"},
Choices={"DIA_A2a2"}, --you can nest tables even further without creating indents in the code
},
DIA_A2a2={
Texts={"generic text again"},
Choices={"DIA_A2b"}, --DIA_A2b is mentioned both as a choice for DIA_A2 and DIA_A2a2, you can have dialogue trees without being restrained by nesting everything
},
DIA_A2b={
Texts={"this is being used by two different dialogues, without having to write it twice"},
Choices={"DIA_A0"}, --and you can even create dialogue loops, want to go back to the first dialogue like games usually do? you can
},
DIA_A2c={
Texts={"i'm out of text ideas"},
--the 'Choices' Table doesn't exist, that also can both save you Lines of code, and be automated to be treated as if it was an empty table, like i explained above
--after all, and empty table is the same as no table at all, it just takes less space
},
},
}