Huge library game concept, with daily reading limitation

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Matt_VoxPrima
Posts: 20
Joined: Tue Apr 22, 2025 3:33 pm

Huge library game concept, with daily reading limitation

Post by Matt_VoxPrima »

Hello!

We're designing a huge medieval library in our game that contains 270 books.

Now, I want to make a mechanic where the player can only read 5 books per day Variable["Theodor.Books_Max"]

And each time the player reads a book he hasn't already read (ex.: Library.Book_EpicOfGilgamesh bool) then I increment Variable["Theodor.Books_Read"] by one. This works fine.

Now, I'm struggling to find the correct way to configure these conditions. It seems any solution I try to apply results in the dialogue box being blank and unable to continue...
Attachments
Capture.PNG
Capture.PNG (159.37 KiB) Viewed 987 times
Capture.PNG
Capture.PNG (388.29 KiB) Viewed 987 times
User avatar
Tony Li
Posts: 23250
Joined: Thu Jul 18, 2013 1:27 pm

Re: Huge library game concept, with daily reading limitation

Post by Tony Li »

Hi,

270 books is a lot of conversations to link. It might be better to handle it in code.

For example -- although you may already be doing this -- you can increment the variable in C#:

Code: Select all

// Call this at the start of each new day:
void StartNewDay() => DialogueLua.SetVariable("Theodor.Books_Read", 0);

// Call this when trying to read a book:
void TryToReadBook(string bookConversationTitle)
{
    int numNewBooksReadToday = DialogueLua.GetVariable("Theodor.Books_Read").asInt;
    var bookVariableName = $"Library.Book_{bookConversationTitle}";
    var hasReadBookBefore = DialogueLua.GetVariable(bookVariableName).asBool;
    if (!hasReadBookBefore)
    {
        if (numNewBooksReadToday >= 5)
        {
            DialogueManager.StartConversation("Can't Read More Books Today");
            return; // Exit early. Can't read any more today.
        }
        else
        {
            // Increment # new books read and mark this book as read:
            numNewBooksReadToday++;
            DialogueLua.SetVariable("Thedor.Books_Read", numNewBooksReadToday );
            DialogueLua.SetVariable(bookVariableName, true);
        }
    }
    DialogueManager.StartConversation(bookConversationTitle);
}
Matt_VoxPrima
Posts: 20
Joined: Tue Apr 22, 2025 3:33 pm

Re: Huge library game concept, with daily reading limitation

Post by Matt_VoxPrima »

I don't mind the monkey work. :) I was dividing my conversations like alleys in an actual library: Library/History, Library/Theology, Library/NaturalScience, etc.

But ok I'll show this to my programmer. Thanks!
User avatar
Tony Li
Posts: 23250
Joined: Thu Jul 18, 2013 1:27 pm

Re: Huge library game concept, with daily reading limitation

Post by Tony Li »

Alleys is smart -- it reduces the number of nodes whose Conditions you need to check when starting the conversation. But it'll be even more efficient if your programmer can implement something like the idea above. And it might be more scalable if you add or remove books.
Matt_VoxPrima
Posts: 20
Joined: Tue Apr 22, 2025 3:33 pm

Re: Huge library game concept, with daily reading limitation

Post by Matt_VoxPrima »

but just for my own curiosity, was there something wrong with using

Variable["Theodor.Books_Read"] < Variable["Theodor.Books_Max"]

for the books that can be read and

Variable["Theodor.Books_Read"] >= Variable["Theodor.Books_Max"]

for when the daily limit has been attained or surpassed?

I'm curious as to why the dialogue manager didn't know what node to pick and returned blank.
User avatar
Tony Li
Posts: 23250
Joined: Thu Jul 18, 2013 1:27 pm

Re: Huge library game concept, with daily reading limitation

Post by Tony Li »

That should work in concept. Maybe there's a typo or something. You could temporarily add a Lua Console to the scene. Then press ~+L to open it, and enter:

Code: Select all

return Variable["Theodor.Books_Read"] >= Variable["Theodor.Books_Max"]
to see what it returns (true or false).
Matt_VoxPrima
Posts: 20
Joined: Tue Apr 22, 2025 3:33 pm

Re: Huge library game concept, with daily reading limitation

Post by Matt_VoxPrima »

Oh wowww that's a thing?!?

That's going to be very helpful! THank you again!
Post Reply