Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected locale-aware string conversions cause problems when calling commands with float variables as arguments in some locales #218

Closed
fmoo opened this issue Dec 31, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@fmoo
Copy link
Contributor

fmoo commented Dec 31, 2022

What is the current behavior?

When using custom commands that expect float parameters in yarn, e.g., <<sleep>> float literals (e.g., <<sleep 0.5>>) behave as expected. However, when using variables (such as <<sleep {$delay}>> in a locale that uses "." as a thousands separator, such as de-AT, the float is converted to a locale aware string (e.g., "0,5") but then back to a float using an InvariantCulture when calling the custom command.

Please provide the steps to reproduce, and if possible a minimal demo of the problem:

Run the following in an OnAwake() somewhere to force the system locale to German (AT).

using System.Globalization;
// ...
        void Awake() {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("de-AT");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("de-AT");
        }

Then in a yarn script:

<<declare $delay = 0.5>>
Let's wait for a half-second...
<<wait {$delay}>>
Done!

The "Done" dialogue will take 5 seconds to appear instead of 0.5 seconds.

What is the expected behavior?

Since we are using a properly typed float variable, and passing it to a command that expects a float, I expect there to be no unnecessary computations of string formatting or parsing to happen, and the "Done" dialogue to appear after a half-second delay instead of five seconds.

Locale aware string formatting would still be expected when using {$value} to format a float var into user-visible dialogue, as well as commands that expect strings/text but a float was passed.

Please tell us about your environment:

  • Yarn Spinner Version: 2.2.1+ (0d39162)
  • Unity Version: 2019.4.36f1

Other information
Link to discord discussion in #help

@fmoo fmoo added the bug Something isn't working label Dec 31, 2022
@McJones
Copy link
Contributor

McJones commented Sep 28, 2023

This was partially fixed as referenced in YarnSpinnerTool/YarnSpinner#369 but the long term issue persists.
For now the format_invariant method provides a workaround until we can come to some long term solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants