Search Unity

Resolved Dynamic Smart String Issue with inputField

Discussion in 'Localization Tools' started by GameOps, Aug 12, 2020.

  1. GameOps

    GameOps

    Joined:
    Dec 24, 2019
    Posts:
    19
    Hi,
    Here is my problem :
    I have a dialog to display on UI, Sentences of the dialog are stored into queue<string> and come from the asset string table of the localization package. In the inspector, I selected all LocalizedString that have to be displayed during my scene in the order of apparition. Here is my code (found on another topic) :

    Code (CSharp):
    1. void EnqueueLocalizedString (Queue<string> queue, LocalizedString[] locStringArray)
    2.     {
    3.         foreach(LocalizedString locstring in locStringArray)
    4.         {
    5.             var op = locstring.GetLocalizedString();
    6.             if (op.IsDone)
    7.                 queue.Enqueue(op.Result);
    8.             else
    9.                 op.Completed += (opex) => queue.Enqueue(opex.Result);
    10.         }
    11.     }
    BUT

    During dialog i made appear an InputField to allow the player to enter a character name. When the field has been filled, i make an assignment to store this value into a class called InputPlayer.

    On the next sentence of the dialog i want to display the character name into the sentence which is marked as "smart". I use {input_name}.

    What i do for it, is clear my queue and re enqueue the rest of the string table.
    InputPlayer class is associated with my dialoguebox where LocalizeString is (like the apples example).

    PROBLEM :
    The character name isn't displayed just like if no assignment was made.

    SUGGESTION :
    When I change the selected locale, the character name appears into the sentence.
    Any idea ?

    I can share more code if needed.
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
    Hi,
    How do you assign the value to the smart string?
    Try changing these so its throw error
    upload_2020-8-12_16-25-15.png
     
  3. GameOps

    GameOps

    Joined:
    Dec 24, 2019
    Posts:
    19
    Hello Karl, thank you for your quick reply.
    I got error, something goes wrong with parsing, see the message below :

    upload_2020-8-12_17-43-58.png

    upload_2020-8-12_17-44-30.png

    I get this twice, once on start, the other when i tried to validate the input by clicking a button.

    How I assign the value to the smart string : like this triggered by a click button

    Code (CSharp):
    1. public void ValidatePlayerInput(){
    2.         if((playerinput.input_name==null || playerinput.input_name=="") && InputNameText.text.Length >0)
    3.         {
    4.             playerinput.input_name = InputNameText.text;
    5.             DialogueSentences.Clear();
    6.             EnqueueLocalizedString(DialogueSentences,SentencesAlarm2);
    7.             WaitForInput = false;
    8.             DialoguePrinter(NameToDisplay,DialogueSentences);
    9.         }
    10.      
    11.     }
    And the InputPlayer Class is added on the dialogbox gameObject and referenced on this gameobject (GameManager)

    ScreenShot of my LocalizationSetting
    upload_2020-8-12_17-52-30.png

    Did I missed a step ?
     

    Attached Files:

  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
    It looks like you are not giving the LocalizedString a reference to playerinput.
    It needs one in order to be able to resolve what input_name is.

    try this
    Code (csharp):
    1.  
    2. void EnqueueLocalizedString (Queue<string> queue, LocalizedString[] locStringArray)
    3. {
    4.     foreach(LocalizedString locstring in locStringArray)
    5.     {
    6.         // Pass in playerinput here
    7.         var op = locstring.GetLocalizedString(playerinput);
    8.         if (op.IsDone)
    9.             queue.Enqueue(op.Result);
    10.         else
    11.             op.Completed += (opex) => queue.Enqueue(opex.Result);
    12.     }
    13. }
     
  5. GameOps

    GameOps

    Joined:
    Dec 24, 2019
    Posts:
    19
    I already saw this instruction in one of your posts but didn't know how to implement it.
    Hope this example will help other members.

    It is now working like a charm.
    Thank you Karl.
     
    karl_jones likes this.
  6. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
    Great. We will make some samples in the future so its clearer.