Forum rules - please read before posting.

Incorrect Journal Indexing

I'm having trouble getting journal pages to appear in the correct order. When adding new journal entries to the journal, pages are being added in the order they were collected in, not the indexing order specified when the journal page was added.

I followed the "Creating a Diary System" tutorial. When the player clicks on the relevant hotspot, it follows this ActionList:

  1. Menu - Change State - Add Journal Page - checked "Only add if not already in?" - Index to insert into: X
  2. Menu - Change state - Turn On Menu
  3. Menu - Set Journal page - Page to set to: Set Here - Page #: X

The X value is the journal's page number. When the journal menu opens it seems to be selecting the correct page number to display, but the order of the pages is incorrectly the order they were collected in. I'm looking for journal pages to be ordered according to their index number regardless of the order they were collected in.

Comments

  • Welcome to the community, @entropy.

    The issue is that the indices you're setting don't exist yet. If you assign an X value of a page number larger than the number of pages it currenly has, then it'll be added to the end.

    A way around this would be to re-order the pages through custom script according to their Line ID as set by the Speech Manager.

    If you use its "Gather text" process to generate IDs for each page, you can use those IDs to set the order the pages should appear in.

    Here's a sample script that may be enough:

    using System;
    using System.Linq;
    using UnityEngine;
    using AC;
    
    public class ReorderJournal : MonoBehaviour
    {
    
        public string menuName;
        public string journalElementName;
        public int[] lineIDs = new int[0];
    
        public void OrderPages ()
        {
            MenuJournal journal = (MenuJournal) PlayerMenus.GetElementWithName (menuName, journalElementName);
            var sortedList = journal.pages.OrderBy (GetSortingKey);
            journal.pages = sortedList.ToList ();
        }
    
        private int GetSortingKey (JournalPage page)
        {
            return Array.IndexOf (lineIDs, page.lineID);
        }
    
    }
    

    To use it, paste into a C# file named ReorderJournal and attach to an empty GameObject.

    Then make it a prefab, remove from the scene, and fill in its Inspector - assigning the names of the Menu/Element to affect, as well as populating the Line IDs array with the IDs gathered by the Speceh Manager (you can find these by setting the Type filter to Journal Entry, in the order you wish for them to appear.

    After adding a new page, you can then use the Object: Call event Action to reference the prefab, calling the ReorderJournal component's OrderPages function.

  • Thank you so much for the excellent write-up!!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.