Forum rules - please read before posting.

Document page number

edited April 2019 in Technical Q&A

Hi there. I'm trying to recreate the Journal page number workflow show in tutorials to use with documents. (I have a working implemented journal page numbers following that).

My C# is quite bad.

I've been trying to just convert directly the scripting, seeing that Journals and Documents work with the same Page logic (or close, or referenced.... my scripting skills bad).

First hitch is that "document" is not considered a menu element, like MenuJournal. So that need a completly different approach.

void Update() { // MenuJournal menuJournal = (MenuJournal)PlayerMenus.GetElementWithName("SocDocument", "PageText"); // KickStarter.runtimeVariables.SetCustomToken(0, menuJournal.GetCurrentPageNumber().ToString()); // KickStarter.runtimeVariables.SetCustomToken(1, menuJournal.GetTotalNumberOfPages().ToString()); Document document = (Document)PlayerMenus.GetElementWithName("SocDocument", "PageText"); KickStarter.runtimeVariables.SetCustomToken(0, document.GetCurrentPageNumber().ToString()); KickStarter.runtimeVariables.SetCustomToken(1, document.GetTotalNumberOfPages().ToString()); }

PS: I don't know the code paste so bad. The first 3 lines are ///d.

Sameways, I don't know if the Get number requests, are to be asked to menujournal or adding the same to the document.cs is gonna work.

Maybe I'm thinking that this is easy but is not. So just a bit of direction will be of help.
(I've tinkered with code for a lot of years but there are so many thinks ones to need to do right in order to debug the code that I can be lost easily)

PS: If requires lots of code (like creating new definitions for the pages of the documents etc, I'll just drop it, It's not a so important feature I need...

Comments

  • You shouldn't need to access the Document class.

    Though the contents of a Document are stored in a separate class, when displayed in a Journal element you can still read the Journal's properties once the Menu is open and displaying the active document.

    You're commented-out lines should work - what was the result of that? You can display their values in the Console with Debug.Log statements, i.e.:

    Debug.Log ("Current page: " + menuJournal.GetCurrentPageNumber().ToString());
    Debug.Log ("Total pages: " + menuJournal.GetTotalNumberOfPages().ToString());
    

    (By the way, the forum will auto-format your code if you have carriage returns and tabs separating each line).

  • edited April 2019

    Damn. Not even seen that "display active document" was a Journal type element, (Problem of using the template to check it, as I didn't create the element).

    so the script it's supposed to work by default?

    I'm getting Object reference not set to an instance of an object

    Question... Are custom tokens crossproject? Because If I reuse the tokens from the regular journal, the document pages text show the pages that has the journal. So I'm guess yes. But when I put new number of tokens, the text just show "token:3" etc... Like the element doesn't have getcurrentpage information... But it is an Journal type element... (Again, I'm using the default template + Label for page numbers.

  • I'm getting Object reference not set to an instance of an object

    I would need the full error message and script to tell what that refers to. Please post your code using pasteall.org, and share the full message.

    Question... Are custom tokens crossproject?

    There really isn't enough information shared here for me to tell what it is you're doing. But a custom token is global for the project.

  • Well, there is no more code to post that the already posted (the commented code is the original working journal page code from yours that I already use for the journal, and the uncommented code is what I tried before knowing Display Active document was a journal type element, when I was trying to tinker the .cs.

    Thing is I tried the original code deriving from this conversation trying to know if it would work as default, then is when the Object reference not set popped up.

    In order to provide you more information, well, any at all, I have to know the answer to the previous question, "Is that code (the one from your tutorial) supposed to work with a "Display Active Document" journal element the same way it works with "New journal" journal element?.

    Because if the answer is no, of course the code won't work.

  • edited April 2019

    Is that code (the one from your tutorial) supposed to work with a "Display Active Document" journal element the same way it works with "New journal" journal element?.

    Yes. So long as you update your Menu/Element names in the script to match the Menu Manager.

    Well, there is no more code to post that the already posted

    There absolutely is. It's not just the critical lines, but the full script - line numbers includeded. Again, I also need the full message, which reveals which line the message is referring to.

  • using UnityEngine;
    using System.Collections;
    using AC;
    
    public class DocumentPageNumbers : MonoBehaviour
    {
    
        void Update()
        {
           MenuJournal menuJournal = (MenuJournal)PlayerMenus.GetElementWithName("SocDocument", "PageText");
            KickStarter.runtimeVariables.SetCustomToken(2, menuJournal.GetCurrentPageNumber().ToString());
            KickStarter.runtimeVariables.SetCustomToken(3, menuJournal.GetTotalNumberOfPages().ToString());
    
        }
    }
    

    Error Message:

    NullReferenceException: Object reference not set to an instance of an object
    DocumentPageNumbers.Update () (at Assets/_GAME/ShadowsCarasia/Resources/Scripts/DocumentPageNumbers.cs:11)

    (the 11º line is the GetCurrentPageNumber.

  • Precede that line with:

    if (menuJournal == null) { Debug.Log ("Cannot find journal"); return; } if (KickStarter.runtimeVariables == null) { Debug.Log ("Cannot find RuntimeVariables"); return }

    What does the Console say? If it's reporting the journal error, then share a screenshot of the "SocDocument" menu / "PageText" element in your Menu Manager.

  • edited April 2019

    Damn, It was just a misspelling. Sorry for wasting your time.
    AC is amazing just as always.

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.