Forum rules - please read before posting.

Special characters in dialogues (from external text file)

I have an external file with text that's meant to be used in dialogues and conversations (see here), and I have some trouble importing special characters.

More specifically, I haven't found a way to import a new line (\n, \r, \r\n, all are displayed as-is) and colon, which is displayed as COLON

Any hints?

Comments

  • How are you transferring the external file into something that's used by AC?

    AC will automatically convert certain characters (such as colons) into unique strings because these characters are also used for separating data. If you want to import a colon character as display text, try replacing it with * COLON * (no spaces) in the text file itself.

  • edited April 2020

    I tried that, and I got "* COLON *" in the dialogue.

    I'm using a TextAsset from Resources, encoded in UTF-8:
    TextAsset ta = (TextAsset)Resources.Load(RiddlesFile, typeof(TextAsset));
    riddles = new List<string>(ta.text.Split(new[] { "\r\n", "\r", "\n" }, System.StringSplitOptions.None));

    I printed each line to the console, and at least the colon shows as it should (new line characters show as "\n").

    Then, I inject the values into parameters like this:
    RiddleGame.GetParameter("Question").stringValue = qData[0];
    (where qData is a string array)

  • What is "RiddleGame" - an asset or scene-based ActionList? And what is your AC version?

    What code you've shared shouldn't be any different from setting the parameter's default value in the ActionList Editor - do you get such an issue when setting a string parameter set to ";;;" directly?

    The colon conversion specifically happens in the AdvGame script's PrepareStringForLoading function - it'd be worth placing a Debug.Log statement in there to reveal where it's being called from.

  • RiddleGame is a scene-based ActionList. And I'm using the latest AC version from the asset store.

    Setting the default value of a parameter to ":" and using it in the "Line text" field of a dialogue, also prints COLON in-game.

    I placed a Debug.Log in PrepareStringForLoading and the colon was printed correctly in the console (as : ). But in the dialogue UI, it was printed as COLON.

  • Setting the default value of a parameter to ":" and using it in the "Line text" field of a dialogue, also prints COLON in-game.

    Odd. That's not the behaviour on my end. Does the log appear for that as well?

    Share the full message, stacktrace included, so we can see where it's coming from.

  • Here you go: https://drive.google.com/open?id=1Vzh5NvbVAUKw75ZwkncagK0fRAya9XMj

    I've put this line inside PrepareStringForSaving:
    Debug.Log("Unprepared string before saving: " + _string);

    The error shown in the console is irrelevant.

    I noticed that, when pressing the PLAY button, the value inside the properties window changes from : to * COLON * (images 1 and 2). Maybe it shouldn't?

  • edited April 2020

    I just noticed that only the PrepareStringForSaving method is called. The PrepareStringForLoading method (which should revert the string to its original form, if I understand correctly) is not.
    I commented out the line _string = _string.Replace (SaveSystem.colon, "*COLON*"); and the colons appeared as they should.

    Also, as I mentioned in the beginning, new line is also an issue. When entering \n inside the "Line text" field, it is working as new line character, but not when it's given as a parameter value. I'm bringing it up in case those two issues share a root cause.

  • FYI (and anyone else interested), I just found a 100% working clean solution for the colon AND the line break issue:

    public void FixText(Speech speech)
    {
        string convertedSpeech = AdvGame.PrepareStringForLoading(speech.FullText);
        convertedSpeech = convertedSpeech.Replace("\\n","\n");
        speech.ReplaceDisplayText(convertedSpeech);
    }
    
    private void OnEnable()
    {
        EventManager.OnStartSpeech_Alt += FixText;
    }
    

    It's still strange why the PrepareStringForLoading is not called, but fixing the string just before it is printed makes sense anyway, so I'm good with that.

    PS: You could add a LINEBREAK conversion in your core script, similar to the COLON one, I think it'll be useful.

  • The solution is only 99% working, after all...

    Putting FixText inside OnStartSpeech_Alt as shown above, causes the [hold] token not to function. Can you suggest a way to fix this?

  • PrepareStringForLoading shouldn't be called, though in this situation likely neither should PrepareStringForSaving. I suspect that with some tweaking, a custom event shouldn't be necessary.

    I'll look into this further.

  • edited April 2020

    I placed the FixText function in OnSpeechToken_Alt instead of OnStartSpeech_Alt and now it's working without breaking the [hold] token.

    public void FixText(Speech speech, string tokenKey, string tokenValue)
        {
            string convertedSpeech = AdvGame.PrepareStringForLoading(speech.FullText);
            convertedSpeech = convertedSpeech.Replace("\\n","\n");
            speech.ReplaceDisplayText(convertedSpeech);
        }
    
            private void OnEnable()
        {
            EventManager.OnSpeechToken_Alt += FixText;
        }
    

    So, as far as my issue is concerned, I'm good. If it is not reproducible on your end, don't bother.

    Thanks.

  • edited April 2020

    Nope, it's not working 100% either. It converts colons inside the "Line text" field, but not the ones that come from string parameters.

    Ok, I give up on trying to fix this without messing with AC native code. This is what seems to be working more consistently:

    (in AdvGame.cs, around line 456)

    //_text = _text.Replace (fullToken, parameter.GetSaveData ());
    _text = _text.Replace(fullToken, parameter.stringValue);
    _text = _text.Replace("\\n", "\n");
    

    Chris, can you confirm that this change won't mess with save data or anything else?

  • It won't affect save data, but it will affect the ability to display non-string parameters.

    Alternative:

    if (parameter.parameterType == ParameterType.String)
    {
        _text = _text.Replace(fullToken, parameter.stringValue);
    }
    else
    {
        _text = _text.Replace (fullToken, parameter.GetSaveData ());
    }
    

    Though, I will be looking to implement something along similar lines in the next release.

  • Thanks a lot.

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.