YarnSpinnerTool / YarnSpinner

Yarn Spinner is a tool for building interactive dialogue in games!
https://yarnspinner.dev
MIT License
2.3k stars 201 forks source link

Proposal: Special character to treat multiple lines as one #339

Closed evilenzo closed 1 year ago

evilenzo commented 1 year ago

Introduction

Currently there is no special character in yarn that makes parser treat multiple lines as one. Since most of languages deal with such problem one way or another we can say that yarn lacks expressiveness. Example:

// C or C++
const char* text = "This string is treated as "
                   "one line string with no line feed.";
# Python
s = "This is a very long line so it would be cool \
    if we split it into two lines but the language will treat it as one."

Rationale

Currently such functionality can be achived by tags and custom views. But it looks like a such common problem that people must solve each time by making their own workarounds. I don't think that such language logic must always be coded by end user.

Proposed solution

We already have \ special character that helps us to show some other special characters to user. Why can't it be also a symbol for treating next line as a part of previous like in python?

This is a long monologue I want to send to my Dialogue View \
as only one line.

Detailed design

It looks like it's a minor change in parser. It should just check the end of a line for this character and then decide to parse or to append next line to this.

Backwards Compatibility

Currently having only one \ character will cause error. So I think it would not affect previous versions.

Alternatives considered

In addition, you can think about other special symbols to make so-called monologue mode that other engines have:

# RenPy

"""
This line is so long so next ones
will be treated as a part of this. Both these lines is only the first line for parser.

But when we face an empty line it makes us to break multiline and continue to the next one. This line is the second one.
"""
st-pasha commented 1 year ago

This sounds like a good idea to me.

McJones commented 1 year ago

We're definitely agreed that having a way to include line breaks in a line is important, for multi-paragraph "lines" in games. However, adding the ability to break a Yarn line across multiple source code lines is less important, and would complicate the parser.

What we think might be a better solution is to provide a text-replacement marker like, for example, [br/] (which doesn't currently exist), which expands out to a newline character.

As a work-around for Unity, it's possible to include TextMeshPro markup to insert a line break right now, using the <br> tag.

Thank you for your well-thought-out proposal!

McJones commented 1 year ago

Closed in favour of #347