Search Unity

Question IF statements for a Visual Novel Program.

Discussion in 'Scripting' started by Mangone, Mar 28, 2023.

  1. Mangone

    Mangone

    Joined:
    Sep 10, 2018
    Posts:
    2
    Hello!

    Hope I am asking in the right place here, and if not, a point in the right direction would be lovely.

    As the tittle says, I am making a visual novel with strategy elements. I'm writing down the story and getting everything together ect.

    Now, I am away from my project computer right now so I am just going to use a little pseudocode.

    public static int verse = 1; //This keeps track of which line of dialogue will be displayed.
    public TMP_Text dialogue; //This will display the dialogue.

    input blah-blah-blah {
    verse = verse +1; // When the player left clicks the mouse or hits space the next line of dialogue is displayed.
    }

    if (verse = 2){
    dialogue.text = " Wait I heard something!"
    }
    if (verse = 3){
    dialogue.text = " Me too, be on your guard."
    }

    My question is : "I'm going to have hundreds maybe even thousands of dialogue. Is using 'if statements' the best manner to go about this? It is easy enough to understand, but will this lead to performance issues later on or some other issue I'm missing? Furthermore, is there just an easier neater way of going about this?

    Thank you very much for your time, hope I am in the right place.
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    This is the Job System forum but I don't see anything related to that in your post.

    I'll move this to the scripting forum.
     
    Bunny83 likes this.
  3. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,648
    It'd be easier to use some sort of collection, like a List, and then add to an iterator. If you make a List of strings and put it in the Inspector, you can even edit it inside of the Unity Editor instead of manually changing the code every time.
     
    Bunny83 and spiney199 like this.
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,938
    To be frank, it won't get you very far.

    Dialogue systems (even visual novels) - on top of involving large amounts of general architecture - needs good editor support to make authoring the text and choices a seamless process.

    At a simple level, the above post is a good starting point. Just a collection of serialised strings, or better yet, a collection of a serialised class.

    At an advanced level, you could be looking at things like node editors for complex dialogue trees, which folks do and have implemented using Unity's experimental graph view API. But that's advanced territory.

    There's a lot of tutorials out there on how to implement a basic dialogue system.
     
    Bunny83 likes this.
  5. Mangone

    Mangone

    Joined:
    Sep 10, 2018
    Posts:
    2
    I see! Not sure what an iterator is, but going to look into it. Editing inside the Unity Editor sound like a much easier task.

    The nice guy bellow you talked about using "serialised strings" which gives me an other good lead on where I should be heading.

    Thank you guys. Looking into a new approach as I type. ^_^