Unity Lua Choice System for my Visual Novel Engine

This topic is 1124 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hello Gamedev-community!

I am working on a Visual Novel engine which originally just worked fine with XML but now shall use Lua.

Thus I try to provide a quite clean scripting interface for myself. I already took some inspiration from the Ren'Py-engine which is using Python.

Though now I ended up with an issue for which my solutions feel dirty or too complicated while there might be a much faster and less complex way.

By the way, I am using Lua as a scripting language passing all the information to C++.

This is how my current Lua-file looks like:


location "school_outdoor"       -- Changes the current location to the outdoor of a school.
blendin ("angry", "y")          -- This blends a new character in, the y is already defined.

y "Hi! How are you?"            -- This is the first dialogue message on the screen.
m "I am fine - how about you?"  -- This will appear once clicking any key.



However when I try to think of a choice system it ends up relying on Lua-tables. On the one side that must not be a bad thing I presume but on the other side it does not feel right.

I am going to try to explain what I want: Let us imagine there are 2 choices (in real there will be more though):

A question would be like: Do you want to eat cake or pizza?

Answer 1: I'd like to eat pizza!

Answer 2: I wanna eat cake!

On each answer there are commands/functions to be done.

Answer 1 or 2 would end up with dialogue message according to the selection and commands to run a different path of the dialogue tree. For example switching to another file/label but also increasing or decreasing stats of the player.

Ren'Py handles it like this:

menu:
$gift = "iguana" b "I'll take an iguana, my good man!" "Buy her a Corn Snake":$ gift = "corn snake"
b "I'll take a Corn Snake, my good man!"


Is there any possibility to provide something similar in Lua? The variables are no deal, but the general structure. I also like how they can declare the choice-state by saying menu:.

I thought about using goto to seperate certain paths in my dialogue tree once an answer got selected.

Currently I am using Lua 5.1, so I would just update it for that.

However goto does not feature variability, like doing goto var in the very beginning of the script. I could not track the current position of the dialogue once the document is closed and then re-entered.

Unless I use a variable representing the label and then run if-loops. Might be a solution but makes it all more and more blown up of code.

In contrast I could just define a new dialogue-file which is planned anyway. Although I wanted to use new files only for completely new sections of the game and huge changes in the storyline.

Is it worth using goto and representing flags (which will be checked the beginning with ifs) to return the current label or is it better to keep everything seperated in new files? Especially: Are Lua-labels considered good or bad design decision?

Thinking about how to structure the choices gave me so many (bad) solutions which would not even fully work out.

For example:

choice "I want a cake."
y "Oh, we can buy one at the store."

choice "I want a pizza!"
y "Pizza is super delicious!"

choice_end

The first choice-function could initiate the choice selection (turn a boolean true) and also add it's string to the first dialogue-variable for choices (maybe in some Lua-table instead of a variable).

Since the choice selection is now true, the  y "Oh, we can buy one at the store." would be stored in the mentioned Lua-table to be executed when the first selection is done. This is the point were I start disliking the idea because I would need a Lua-table and I feel like I am thinking way too complicated. I would have to check what entries in the table are the choices and then find their according commands.

Finally the choice_end would stop the searching for new choice-functions.

Is using a Lua-table to store all the data in a rather bad solution? Would it not be a quite slow method to operate that much with a Lua-table? This questions is a bit related to the first, too.

Thanks for taking your time to read this thread and I hope you might know some solution and could explain how I could tackle my issue.

Edited by Angelic Ice

Share on other sites

Thanks for taking your time to reply Alberth. I will look into LPEG.

However why did somebody vote your post down? I am a bit confused now whether what you suggested is bad or a good thing to do.

Can anyone tell me why this post may got voted down?

Share on other sites
So I notice, maybe I shouldn't have moved to discussing DSLs or so? No idea, tbh

Share on other sites
Honestly, he provided a really good answer. I guess some people are just feeling hateful? Voted up. Edited by Tangletail

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 9
• 23
• 9
• 32
• Forum Statistics

• Total Topics
632620
• Total Posts
3007497
• Who's Online (See full list)

There are no registered users currently online

×