Your approach will quickly become unmanageable as the number of messages in a conversation grows, because the tables become very deeply nested which is hard to read/understand, and even hard to see because of indentation. It’s also limited because you can’t have cycles in the dialogue tree, or branches that combine (two different choices can never lead to the same response).
You could come up with different schemes, but IMO you’ll end up with something that’s annoying and error-prone to edit no matter what. I’d use a dialogue editor instead, only trouble is finding one that exports to Lua. Here’s a reddit thread with a bunch of suggestions: Reddit - Dive into anything
I haven’t used it, but Yarn seems to be quite good: GitHub - YarnSpinnerTool/YarnEditor: Forwarding repository for @blurymind/YarnClassic
If you don’t want to deal with external tools, I’d use a structure like this:
local Messages = {
--Tom
[1] = {
Text = "How are you doing?",
Answers = {2, 3, 4},
},
[5] = {
Text = "Nice to know you're doing good",
Answers = {8},
},
[6] = {
Text = "Oh, I'm doing fine too",
},
[7] = {
Text = "I know right?!",
},
--Player, speaking with Tom
[2] = {
Text = "Good",
Answers = {5},
},
[3] = {
Text = "Fine",
Answers = {6},
},
[4] = {
Text = "Awesome",
Answers = {7},
},
[8] = {
Text = "Thanks",
}
}
Using descriptive IDs rather than just numbers quickly becomes very hard, and slows down the editing process. Explicitly giving each message a numeric ID rather than just using their order in the table means you can move things around (you can probably see that’s exactly what I did). You’re not limited to using only numbers either, you can choose strings for a select few options you want to describe, and numbers for the rest.