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

Format function added to the standard library #348

Closed McJones closed 7 months ago

McJones commented 1 year ago

Is your feature request related to a problem? Please describe.

As discussed in PR #335 there does need to be a way to format values for inline expressions. This offers an alternate approach, using a new built in function that will take in two parameters, a format string (syntax to be determined) and a value of any type. It will return a string formatted appropriately.

Describe the solution you'd like

So the following line in Yarn dialogue

Number: {format("%04d", 86)}

Would be rendered as:

Number: 0086

Describe alternatives you've considered

Alternatives are discussed and proposed in PR #335 and take the form of either creating new markup or adding new language syntax for inline expressions.

Additional context

Thanks to @salyu9 and @st-pasha for their discussion and contributions to this.