Search Unity

Resolved Error parsing format string...

Discussion in 'Localization Tools' started by kouresearch, Nov 25, 2020.

  1. kouresearch

    kouresearch

    Joined:
    Dec 18, 2018
    Posts:
    8
    Hi, I'm trying to use smart string (in localization tools preview 0.9.0) but getting error below :

    FormattingException: Error parsing format string: Could not evaluate the selector "remainDay" at 1
    {remainDay} {remainDay:day|days} {remainHour} {remainHour:hour|hours} {remainMinute} {remainMinute:minute:minutes} left


    The LocalizeStringEvent component is attached to a Text object and Format arguments has size 1 and linked to some gameObject that has public int variable remainDay and so on.

    I can't figure out what I'm doing wrong... plz help!
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,292
    Sounds like you want to link the argument to the Component, not the GameObject.
    Drag the component into the slot. You can open 2 Inspectors if the Component is on a different GameObject.
     
  3. kouresearch

    kouresearch

    Joined:
    Dec 18, 2018
    Posts:
    8
    Cool! Problem solved. Thanks for the quick reply! :)
     
    karl_jones likes this.
  4. vaibhavgovind28

    vaibhavgovind28

    Joined:
    Apr 10, 2018
    Posts:
    1
    Hi @karl_jones, I am facing the same issue but in the current version, I am not able to see the Format arguments list here in Localize string event component.
     

    Attached Files:

  5. MylesLambert

    MylesLambert

    Joined:
    Dec 31, 2012
    Posts:
    61
  6. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,292
    I'm not sure I understand the problem. What are you trying to do?
     
  7. WildRaion

    WildRaion

    Joined:
    Sep 27, 2020
    Posts:
    2
    Hello, how can I use a static class script as an object reference. When trying to move the script to the object reference field, then called in the smart string, an error appears: "Error parsing format string: Could evaluate the selector". What am I doing wrong?

    The code of PlayerData.cs
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public static class PlayerData
    4. {
    5.     public static int CurrentScore
    6.     {
    7.         get
    8.         {
    9.             return PlayerPrefs.GetInt("currentScore", 0);
    10.         }
    11.         set
    12.         {
    13.             PlayerPrefs.SetInt("currentScore", value);
    14.         }
    15.     }
    16. }
    17.  
    2021-11-10 18_16_26-Testing - BackgroundScaler - Android - Unity 2020.3.16f1 Personal_ _DX11_.png 2021-11-10 18_17_03-Testing - BackgroundScaler - Android - Unity 2020.3.16f1 Personal_ _DX11_.png
     
    Last edited: Nov 10, 2021
  8. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,292
    It took me a moment to understand what you were doing then. Are you dragging your script into an Object Reference field? That wont work, it will treat it as a TextAsset I belive. You cant access static classes through smart strings but you can create a custom Persistent Variable to do it and then use that instead of an ObjectReference.
    Take a look at the examples https://docs.unity3d.com/Packages/c...ables-Source.html#custom-persistent-variables

    Something like this should work

    Code (csharp):
    1. [DisplayName("Player Data")]
    2. public class PlayerDataVariable : IVariable
    3. {
    4.     public string xmlText;
    5.  
    6.     public object GetSourceValue(ISelectorInfo selector)
    7.     {
    8.         return PlayerPrefs.GetInt("currentScore", 0);
    9.     }
    10. }
    Then you wont need to use reflection so can just do `global.playerData` assuming the variable is called `playerData`
     
  9. WildRaion

    WildRaion

    Joined:
    Sep 27, 2020
    Posts:
    2
    Thanks for the quick reply! It really helped. Now I figured out how to use it.

    Yes, that's exactly what I did, I realized that this is clearly not how it should work :rolleyes:
     
    karl_jones likes this.
  10. drewjosh

    drewjosh

    Joined:
    Sep 24, 2019
    Posts:
    30
    Hello there,

    After updating from version 0.9 to 1.0.5 the Format arguments list of the class "Localize String Event" are gone and I can't get to work my translation. I have a script with the property distance. When I click preview or Play app I get this error:

    Here my component settings and script:

    Component
    Bildschirmfoto 2022-05-30 um 10.36.20.png

    Script
    Bildschirmfoto 2022-05-30 um 10.36.26.png

    The SetDistance(int) is called from a controller script in the scene.

    I don't understand why it doesn't work anymore? (I added a local variable with the Object reference but it looks like something is missing still?)
     
  11. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,292
    the variable "distance" will reference the instance of the class, not the variable distance. So you need to do
    {distance.distance:plural....}

    Its also worth updating to 1.3.1 since that is the latest and 1.0.5 is quite old now.
     
    drewjosh likes this.
  12. drewjosh

    drewjosh

    Joined:
    Sep 24, 2019
    Posts:
    30
    That was it! You are an amazing person. Thanks for the quick reply!

    Update is in progress :) (I was actually already on 1.2.1 so not too bad ;) )
     
    Last edited: May 30, 2022
    karl_jones likes this.
  13. Ghouti

    Ghouti

    Joined:
    Oct 25, 2019
    Posts:
    1
    Hello! I'm using smart string too, but I'm getting this error :

    FormattingException: Error parsing format string: Could not evaluate the selector "offerPrice" at 41
    Votre credit de recharge sera debite de {offerPrice} !

    The LocalizeStringEvent component is attached to a Text object.

    Can I know what I'm doing wrong?
     

    Attached Files:

  14. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,292
    It looks like you have a reference to the GameObject, not the component. You need to drag the component in. You can do this by opening another inspector and locking one with the little padlock icon at the top.
     
    Baykus likes this.