Menu structure
Posted: Sun Apr 26, 2015 5:41 pm
Hey, what would be the best way of structuring a npc dialogue menu tree?
Code: Select all
shopkeeperDialogue = {
text = "Hello! How may I help you?",
choices = {
{
text = "Buy Item",
dialogue = {
text = "What would you like to buy today?",
choices = {
{
text = "Sword",
action = buySword,
dialogue = {
text = "Here's your sword. Thank you for your purchase!",
},
},
{
text = "Shield",
action = buyShield,
dialogue = {
text = "Here's your shield. Thank you for your purchase!",
},
},
},
},
},
{
text = "Who are you?",
dialogue = {
text = "I'm the weapons keeper. You can buy swords or shields from me.",
},
},
},
}
Code: Select all
function buySword()
print "You've bought a sword!"
end
function buyShield()
print "You've bought a shield!"
end
shopkeeperDialogue = {
text = "Hello! How may I help you?",
choices = {
{
text = "Buy Item",
dialogue = {
text = "What would you like to buy today?",
choices = {
{
text = "Sword",
action = buySword,
dialogue = {
text = "Here's your sword. Thank you for your purchase!",
},
},
{
text = "Shield",
action = buyShield,
dialogue = {
text = "Here's your shield. Thank you for your purchase!",
},
},
},
},
},
{
text = "Who are you?",
dialogue = {
text = "I'm the weapons keeper. You can buy swords or shields from me."
},
},
},
}
local dialogue = shopkeeperDialogue
while dialogue do
print(dialogue.text)
if dialogue.choices then
for i,choice in ipairs(dialogue.choices) do
print(i, choice.text)
end
io.write('> ')
local choiceNum = io.read('*n')
local choice = dialogue.choices[choiceNum]
if choice then
if choice.action then
choice.action()
end
dialogue = choice.dialogue
end
else
dialogue = nil
end
end
Maybe you mean Twine: http://twinery.org/S0lll0s wrote:There is this HTML-JS interactive storytelling engine whose name I forgot; it's basically a dialogue system. It has an editor but no way to save or export the result other than HTMl AFAIK, so you would need to write a little JS export and a fitting Lua library.
Yes! I think that was it.Muris wrote:Maybe you mean Twine: http://twinery.org/S0lll0s wrote:There is this HTML-JS interactive storytelling engine whose name I forgot; it's basically a dialogue system. It has an editor but no way to save or export the result other than HTMl AFAIK, so you would need to write a little JS export and a fitting Lua library.
Making branching story telling doesn't sound exactly easy to do thing. You probably need to have a states for various choices, not to mention a possibility to skip some of the things you've planned. Maybe player doesn't do something you expect or skips some part of the game. The simpler you make, the easier it is to control the thing.
There was similar topic in the forum couple of months ago, but sadly I wasn't able to actually find the topic. Maybe finding that topic could give bit more info.