Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Write a String to an array

Discussion in 'Scripting' started by KnightRiderGuy, Sep 7, 2018.

  1. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514
    I'm trying to work out a good method to have a character remember any set of characters given to it such as initials or even a number sequence like a telephone number.

    something like this:

    I would say to my character:
    "remember this set of initials"
    my character would then say:
    "Go ahead"
    And then I would say:
    "B, E, R, (Or anything)

    My first thought is to have an alphabet array of all 26 letters
    and then maybe a 2nd array that would keep a string of any character given to it like in my method (Above)

    But not sure what the best way to go about both implementing the array set up and retrieval method for getting those initial later on to perhaps print out on the screen by voice command.

    Any thoughts?
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,378
    Strings are already arrays of the char type. They're indexed and everything.

    Why not just use a string?

    ...

    Unless there's something I'm missing here. I don't fully get what your intent is from this:
    Who are any of these pronouns? How does this correlate to game logic? What is going on here?
     
  3. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514
    Sorry I guess I didn't make that clear enough.

    Let's say I have an A.I.
    That I want to get to remember any set of initials or numbers I tell it,
    For instance if I was to say to you:

    I want you to remember these numbers, and then I wait for you to say something like: "OK, go ahead"
    and then I tell you what number or initials and then you remember them and I can ask you what they were later on.

    Can't really make it any clearer than that.

    :)
     
  4. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,378
    Well, there's a lot more than just the saving of those going on there.

    There's the entire interaction/back and forth. The saving the sequence at the end is honestly the easiest part. Just save it as a string.

    Code (csharp):
    1. string memory = "BER";
    Strings are literally arrays, you can still access each character just like an array:
    Code (csharp):
    1.  
    2. foreach(char c in memory)
    3. {
    4.     Debug.Log(c);
    5. }
    6.  
    Code (csharp):
    1. Debug.Log("The second letter is: " + memory[1]);
    And if you really are hard set on it being a pure array, there is ToCharArray:
    https://docs.microsoft.com/en-us/do...=netframework-4.7.2#System_String_ToCharArray
     
  5. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514
    Yes that would be simple enough if I had a specific set of initials or numbers in every case however in each case the numbers or initials may vary.
     
  6. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514
    I can use a method similar to that to write each character to a location in an array but I'm not sure that might be the best method for when it comes to retrieving that series of letters or numbers.
     
  7. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,378
    You build it as they input the values.

    Ohhhh... ok. You're not asking how or what to store it as.

    You're asking how to retrieve those values from the user?

    So yeah, you're not asking how to store it. You're asking the lead up steps. How you do all those steps. Which is why I was lost... cause I'm like, all that lead up is the hard part. Yet your original question just the simple: "Write a String to an array".

    ...

    As for that lead up. That's a lot of adhoc specifics relative to you.

    How does you player interact? Is this a 3d world and they walk up and press an interact button? How does interaction display on screen? Do you have a dialog system in your game? Do you have a text input system in your game?

    All of these are very non-trivial. And they're very specific to YOUR game. We don't know your game at all.

    I could give very rough ideas of how you do it. Like for instance just have a coroutine that loops and waits for keyboard inputs. Something along the lines of:

    Code (csharp):
    1.  
    2. IEnumerator ListenForInputSequenceUntilEnterIsPressed()
    3. {
    4.     string sresult = "";
    5.     while(true)
    6.     {
    7.         if(Input.GetKeyDown(KeyCode.Return)) break;
    8.      
    9.         string sval = Input.inputString;
    10.         if(!string.IsNullOrEmpty(sval))
    11.         {
    12.             sresult += sval;
    13.         }
    14.         yield return null;
    15.     }
    16.     Debug.Log(sresult);
    17. }
    18.  
    This is very basic and doesn't do anything with the data, nor does it handle any special keys. There is a more in depth example at the doc page:
    https://docs.unity3d.com/ScriptReference/Input-inputString.html
     
    KnightRiderGuy likes this.
  8. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514
    Thanks,
    Yeah sort of.
    let me see if I can explain a little more of what is going on.
    I'm using an A.I. voice recognition in order to be able to talk to my app,
    Now I can say an insane amount of things to it and get various responses based on all kinds of parameters such as mood, context a particular thing that is being said to it or asked and so on.....
    I even have a guess my number game I can play with it where he chooses at random a number between 1 & 10 and then I have to guess what it is.

    But this is another thing I am tinkering with ideas on how best to approach it and that is to mention either numbers or letters and then have him remember these numbers and or letters at any other time I ask him what they were.

    So it kinda gets crazy complicated from there ;)
     
  9. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,378
    See this:
    This is important information.

    You say earlier:
    Yes you can, you could include the information that you're using a VOICE RECOGNITION system. This is very critical to your problem.

    Also, what voice recognition system are you using? Is it your own custom making and we therefore know nothing about it? Or is it a 3rd party library with a documented API? Do you have a link to that API?

    Information dude... we need it.

    Yep, so how the heck are we supposed to GUESS your situation???
     
    KnightRiderGuy likes this.
  10. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514
    Sorry My bad ;)

    It's custom,
    But the VR inputs as commands that get handles as cases so say I might have case for a command like:

    Code (CSharp):
    1. case "CharIs_A":
    2.  
    3.        // Method for writing character to string array to be retrieved later
    4.  
    5. break;
    6.  
    7. case "CharIs_E":
    8.  
    9.        // Method for writing character to string array to be retrieved later
    10.  
    11. break;
    12.  

    ….. So on

    in each case I can have any number of voice commands to trigger each case say something like:

    "The first letter is A"
    or
    "The first one is A"
    Or
    "First letter is an A buddy"

    etcetera

    This'll give you a little better idea of the craziness I'm working with ;)
     
    Last edited: Sep 7, 2018
  11. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    Having only watched the first 90 seconds (of this half hour video), it would seem that you are not really asking about storage and retrieval of data - you are asking about a fully fledged, hyper-complex human-machine AI interface.

    For example, presumably you want your system to respond correctly to "This command is a lie". The analysis and a fully coherent, intelligent response to such a conundrum is way beyond the scope of storing the individual characters that form the string and handling the result with a
    switch
    statement.

    I think this problem is simply beyond the scope of these forums and is well beyond simple (or even complex!) scripting. You would be better off looking into some courses dedicated to AI research- here is a list of some free online ones.
     
  12. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514
    I tend to disagree, if you had watched more than 30 seconds you would realize that because I have this where it can learn things, remember data and then retrieve that data, albeit in a simulated fashion and only using scripted conversation there are many, many things I CAN have this do, the video clearly demonstrates that if one had taken the time to actually watch it.

    Kind of like the "Who's on first" scenario, it's a work in progress and is very complex but I can have this pretty much do the entire routine and he does eventually get "Who's on first."
    Even the guess my number scenario is nothing more than data storage and retrieval. So when you say:
    "Beyond the scope"

    You're just not imaginative enough.

    But hey, thanks for your input though :/
     
    Last edited: Sep 7, 2018
  13. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    First up - humble apologies if I have misread your situation. :oops: In my defence, I thought you had posted a video of someone who had produced something you were aspiring to achieve- I presume now that is your good self in the video?

    However, now I find myself somewhat bemused. :) If you already have an AI system that is listening to spoken input and responding intelligently, then I'm at a loss to understand why you are asking about storing strings and retrieving them. Surely you are way beyond that stage now with this system?

    Unimaginative or not, I wish you well with your project. :D
     
    KnightRiderGuy likes this.
  14. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514

    No trouble man,
    You are correct that's me in the video, your friendly neighborhood mad scientist guy lol
    I'm not really a scientist but I play one in real life ;)

    Well I already know how to do it I'm in fact doing similar things using arrays and strings to store and retrieve data but I figured I would put it out there to the unity community to see if there are perhaps other ideas of thought, different ideas on how to use the arrays and strings more effectively.

    Now like I say I'm just tinkering with this idea but one way I figure to store each character sequentially to an array is something like this:

    Code (CSharp):
    1. // Alphabet
    2.     public string[] alphabet =
    3.     //A    B    C    D    E    F    G
    4.     {"A", "B", "C", "D", "E", "F", "G",
    5.     //H    I    J    K    L    M    N
    6.      "H", "I", "J", "K", "L", "M", "N",
    7.     //O    P    Q    R    S    T    U
    8.      "O", "P", "Q", "R", "S", "T", "U",
    9.     //V    W    X    Y    Z
    10.      "V", "W", "X", "Y", "Z"};
    11.  
    12.     // Numbers
    13.     public string[] numbers =
    14.     {//0   1    2    3    4      
    15.      "0", "1", "2", "3", "4",
    16.     //5    6    7    8    9  
    17.      "5", "6", "7", "8", "9"};
    18.  
    19.     // Letters To Remember
    20.     public string[] CharsToRemember = new string[26];
    21.     // Numbers To Remember
    22.     public string[] NumeralsToRemember = new string[10];
    23.  
    24.  
    25.  
    26.  
    27.  
    28.     // Add Character To "CharsToRemember" Array
    29.     public void AddChar_A()
    30.     {
    31.         CharsToRemember[0] = "A";
    32.  
    33.     }
     
  15. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514
    But I guess I'm thinking more along the lines of having the characters and number I may want saved stored sequentially in the way they would be spoken into a single string that could then be saved, there are SO many ways to do it the mind boggles lol
     
  16. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    So it looks like the code lordofduct gave in post #7 is a pretty good template for what you want. You could also consider using a StringBuilder for this purpose.
     
    KnightRiderGuy likes this.
  17. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514
    Yes correct,
    I really like that idea too because it does allow me to store a particular string into a specific array slot, say in this case slot 0

    like this:

    Code (CSharp):
    1. IEnumerator ListenForInputSequenceUntilEnterIsPressed()
    2.     {
    3.         string sresult = "";
    4.         while (true)
    5.         {
    6.             if (Input.GetKeyDown(KeyCode.Return)) break;
    7.  
    8.             string sval = Input.inputString;
    9.             if (!string.IsNullOrEmpty(sval))
    10.             {
    11.                 sresult += sval;
    12.             }
    13.             yield return null;
    14.         }
    15.         Debug.Log(sresult);
    16.         CharsToRemember[0] = sresult;
    17.     }
     
  18. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514
    This way if say there was already a set of characters saved in array slot 0 I could then save a 2nd set into slot 1 and so on, I can't imagine me needing any more than say maybe 3 or 4 slots to save such things in, maybe just something like:

    Name, or initials slot 0
    address slot 1
    phone number slot 2
    maybe a couple more for some simple additional information

    I would just need to change the key stroke inputs to use my VR inputs instead but I think that method would work, might be a bit tricky, but I'll play around with it.

    Any other ideas out there guys?
    Always open to new ideas :)
     
    Last edited: Sep 7, 2018
  19. Fido789

    Fido789

    Joined:
    Feb 26, 2013
    Posts:
    343
    I can't say I fully understand your intentions, but it seems to me that you should get back to post #2 in this thread and reread @lordofduct 's post. You want to store sequence of characters, not strings, so you should not use string[], but pure string, string IS sequence of characters.
     
  20. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514
    Yes I mentioned in post 17 I like his idea ;)
     
  21. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514

    Is there an elegant way to use a different type of input instead of key presses?
    Say something like a command directly from each case where I call each letter/character as needed?
     
  22. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,378
    I thought you had already said you have a voice recognition system so you can talk to this software of yours. And you even said you built it.

    Voice recognition already has an IO system to it... it's the whole "recognition" part. Usually using a microphone as the hardware input, speakers as the hardware output, and a complex linguistic algorithm to decipher the words being said.

    I fail to see how you were able to build all that... and not have an elegant way to decipher letters from it.
     
    Suddoha likes this.
  23. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514
    The back end VR part I never built, just the processing on the inputs part.
    So my knowledge is a little sketchy when it comes to certain processing elements :/
     
  24. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,378
    OK...

    So then I repeat my post from the beginning.

    WE NEED MORE INFORMATION.

    Like what is this back end voice recognition? Does it have documentation of its API? etc, etc, etc, etc, etc, we're not in your brain.
     
  25. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514
    No idea on that
    But I do know that the processes are being read as cases

    example if something is said:

    "Hello there" for example it gets processed in Unity as a case so each case would be something like:

    Code (CSharp):
    1. case "HelloThere":
    2.  
    3.        // Process the VR input with If statement etcetera
    4.  
    5. break;
     
    Last edited: Sep 8, 2018
  26. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,378
    You don't know the Voice Recognition software you're using?

    . . .

    This is like trying to answer a question about car problems when we don't know the make, model, year, transmission, engine style, or even the colour of the dang car.

    What do you expect in return?

    Sure we could all just shoot in the dark here and talk about the concept of repairing a car on an abstract level. But why? It's not going to answer your problem unless accidentally so. And even if it does, all it does is reinforce this behaviour of yours where you don't offer up information, and expect others to still return information. A detestable behaviour that I would hate to condone.
     
  27. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514
    like I said it's custom and I never designed that part of it so I'm not sure what more I can say about it...

    anyways we're getting off topic I'm asking:
    if anyone had any ideas and thoughts on how best to save each character sequentially to an array with each case being an input for each letter or number as the case may be.


    How the back end VR works has no bearing on that at all.

    ONLY how it's processed inside of Unity and I've already answered that. "Cases"
     
    Last edited: Sep 8, 2018
  28. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,378
    And this was answered way at the beginning of the thread.

    As a string.

    Because a string is a sequential array of characters.

    But that's NOT what you're asking, you're not talking about storing them. You're talking about how to interpret them to be stored.

    Sure it does, as you're asking about using it versus a keyboard. Well, we don't know what IT is, we don't know how it's IO works. We don't know how you receive commands from it. How could we say what is the best way to get data from it if we don't know what it is.

    "cases"

    Yes, and if statements. And "War & Peace" was written using an alphabet. And cars are built using steel. And houses using wood. And you can store sequences of characters as a string. (note how vague descriptions basically go no where)

    I don't see how this is "getting" off topic. It hardly has a topic in the first place. I'm honestly trying to FIND the topic.
     
  29. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    I have to say, I'm in agreement with lordofduct. I'm not clear on what the exact problem is we're trying to solve. :)

    The answer to this, as has already been stated, is a
    string
    as it is an array of type
    char
    (that is a C# type as opposed to meaning a letter from the alphabet).

    However, this sounds like some sort of lookup, or mapping, is required but it isn't clear what that is.

    Could you provide a simple but concrete example, or use case, for us to analyse.
     
    KnightRiderGuy and lordofduct like this.
  30. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514
    Never mind,
    I know what I need
     
  31. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514
    Well, more than one way to skin a cat.
    It may not be the most elegant wat to do this but it will work with my VR inputs.
    I'll have a command to start the listening for characters process and once done I'll have a command for letting the A.I. know that I'm done reading characters, this will then save the characters in an array slot for retrieval later.
    Something like this.
    Of course I'm open to other ideas from the community ;)

    Code (CSharp):
    1. // Letters To Remember
    2.     public string[] CharsToRemember = new string[5];
    3.     // Numbers To Remember
    4.     public string[] NumeralsToRemember = new string[5];
    5.  
    6.     public bool LettersToRemIsDone = false;
    7.  
    8.  
    9.     public void StartRememberChars()
    10.     {
    11.         // Set The LettersToRemIsDone To False
    12.         LettersToRemIsDone = false;
    13.         StartCoroutine(ListenForInputSequenceUntilDone());
    14.     }
    15.  
    16.  
    17.     // Add Character To "CharsToRemember" Array
    18.     public void AddChar_A()
    19.     {
    20.         sresult += "A";
    21.     }
    22.     public void AddChar_B()
    23.     {
    24.         sresult += "B";
    25.     }
    26.  
    27.     public void DoneGivingChars()
    28.     {
    29.         // Set The LettersToRemIsDone To True
    30.         LettersToRemIsDone = true;
    31.     }
    32.  
    33.     // Exp.
    34.     string sresult = "";
    35.     IEnumerator ListenForInputSequenceUntilDone()
    36.     {
    37.         // Wait Time
    38.         yield return new WaitForSeconds(0.5f);
    39.         // Reset Sctring For New inputs
    40.         sresult = "";
    41.         while (true)
    42.         {
    43.             if (LettersToRemIsDone == true) break;
    44.  
    45.             string sval = Input.inputString;
    46.             if (!string.IsNullOrEmpty(sval))
    47.             {
    48.                 sresult += sval;
    49.             }
    50.             yield return null;
    51.         }
    52.         Debug.Log(sresult);
    53.         CharsToRemember[0] = sresult;
    54.     }
     
  32. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    Ok, that looks pretty good. I have taken the liberty of rewriting it in an alternate manner. This is exactly the same as above just worded slightly differently.
    Code (CSharp):
    1.     public void StartRememberChars()
    2.     {
    3.         DoneGivingChars();
    4.         m_remembering = StartCoroutine(ListenForInputSequenceUntilDone());
    5.     }
    6.  
    7.     public void DoneGivingChars()
    8.     {
    9.         if(m_remembering != null)
    10.         {
    11.             StopCoroutine(m_remembering);
    12.             m_remembering = null;
    13.         }
    14.     }
    15.  
    16.     IEnumerator ListenForInputSequenceUntilDone()
    17.     {
    18.         yield return m_wait;
    19.         m_sremembered = "";
    20.  
    21.         while (true)
    22.         {
    23.             string sval = Input.inputString;
    24.  
    25.             if (!string.IsNullOrEmpty(sval))
    26.             {
    27.                 m_sremembered += sval;
    28.             }
    29.  
    30.             yield return null;
    31.         }
    32.     }
    33.  
    34.     readonly WaitForSeconds m_wait = new WaitForSeconds(0.5f);
    35.     Coroutine m_remembering;
    36.     string m_sremembered;

    Based on that, maybe I could make a few observations?
    1. The array of numerals is not used. But numerals are just chars (in the C# type sense) so would fit in the 'remembered' string anyway.
    2. The array of strings is never fully utilised. Only the first element (index zero) is used. Hence, I removed the array and just kept one storage string.
    3. The 'remembered' string is being added to in the coroutine from the
      Input
      object. There appears to be no need for the methods to explicitly add characters. But if there is, then only "A" and "B" can be added. Is that intentional?
    4. It seems more prudent to use a couroutine variable to monitor the coroutine running than having a separate bool. But this may just be a matter of taste. I made the change purely to show something different.
    Edit: just realised I didn't give an accessor for the 'remembered' string. :rolleyes:
     
    KnightRiderGuy likes this.
  33. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514
    Edit:
    Thanks
    Sorry for the late reply I was up to my eyeballs adding in all the VR commands for each character sort of like:
    "The first letter is Alpha"
    "the next letter is Alpha"
    And so on since there is no guarantee one may follow or precede the other ;)
    I then had to add the processes in each case input

    I had originally created the arrays of Alphabet and numerals as a more "Just in case" scenario as I was not sure what method I was going to use or need to do this. So they are not really needed but I'm just leaving them in the script for now just in case I come up with some other way of doing this.

    I had just put in the inputs for "A" and "B" just to test to make sure my character calls would be read through the VR input or commands script.
    But I intend to make the entire alphabet as inputs,
    I did discover that saying each character only works to a small degree, I'll need to use the military method of VR'ing the characters like
    Alpha
    Bravo
    Charlie
    ……. etcetera otherwise "B" & "E" sound too similar even though I have the validity threshold quite high.

    Sorry my use of bools is just something I have gotten very familiar with, either those or Enums depending on how many variable I may have in other scenarios.

    I like your method of stopping the listening coroutine much better though. :)

    I'm also going to need to come up with a command for if KITT misunderstands a character input command.
    Fortunately I do have a voice command for:
    "I think you misunderstood what I just said pal"
    And that I guess I can have drill down to another if statement that checks to see if he's listening for characters and if he is then delete the last character that was input into the string,
    Maybe even have even have him say something like:
    "Sorry Michael, would you care to try again"
    And then re-read the character input.
    VR sometimes can be a little dodgy if the inputs sound too similar even with the high validity threshold.
    But I did manage input most of the alphabet VR inputs using the Military method and then test it out. apart from him misunderstanding a few of them, most fired off OK. I think some of that might just be the VR still needs to learn my speech for those as a further test this morning revealed that he caught a lot more of them from yesterday evening's test.
     
    Last edited: Sep 10, 2018
  34. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514
    I was messing about with your method but I don't think I was getting it to jive with what I had lol
    I'm probably missing something REALLY simple, I'm too close to this stuff sometimes can't see the forest for the trees ;)

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class RememberThisManager : MonoBehaviour {
    7.  
    8.     // Alphabet
    9.     public string[] alphabet =
    10.     //A    B    C    D    E    F    G
    11.     {"A", "B", "C", "D", "E", "F", "G",
    12.     //H    I    J    K    L    M    N
    13.      "H", "I", "J", "K", "L", "M", "N",
    14.     //O    P    Q    R    S    T    U
    15.      "O", "P", "Q", "R", "S", "T", "U",
    16.     //V    W    X    Y    Z
    17.      "V", "W", "X", "Y", "Z"};
    18.  
    19.     // Numbers
    20.     public string[] numbers =
    21.     {//0   1    2    3    4      
    22.      "0", "1", "2", "3", "4",
    23.     //5    6    7    8    9  
    24.      "5", "6", "7", "8", "9"};
    25.  
    26.     // Letters To Remember
    27.     public string[] CharsToRemember = new string[5];
    28.     // Numbers To Remember
    29.     public string[] NumeralsToRemember = new string[5];
    30.  
    31.     public bool LettersToRemIsDone = false;
    32.  
    33.  
    34.     public void StartRememberChars()
    35.     {
    36.         // Set The LettersToRemIsDone To False
    37.         LettersToRemIsDone = false;
    38.         StartCoroutine(ListenForInputSequenceUntilDone());
    39.  
    40.         //DoneGivingChars();
    41.         //m_remembering = StartCoroutine(ListenForInputSequenceUntilDone());
    42.     }
    43.  
    44.  
    45.     // Add Character To "CharsToRemember" Array
    46.     public void AddChar_A()
    47.     {
    48.         sresult += "A";
    49.         //m_sremembered += "A";
    50.     }
    51.     public void AddChar_B()
    52.     {
    53.         sresult += "B";
    54.         //m_sremembered += "B";
    55.     }
    56.     public void AddChar_C()
    57.     {
    58.         sresult += "C";
    59.         //m_sremembered += "C";
    60.     }
    61.     public void AddChar_D()
    62.     {
    63.         sresult += "D";
    64.         //m_sremembered += "D";
    65.     }
    66.     public void AddChar_E()
    67.     {
    68.         sresult += "E";
    69.         //m_sremembered += "E";
    70.     }
    71.     public void AddChar_F()
    72.     {
    73.         sresult += "F";
    74.         //m_sremembered += "F";
    75.     }
    76.     public void AddChar_G()
    77.     {
    78.         sresult += "G";
    79.         //m_sremembered += "G";
    80.     }
    81.     public void AddChar_H()
    82.     {
    83.         sresult += "H";
    84.         //m_sremembered += "H";
    85.     }
    86.     public void AddChar_I()
    87.     {
    88.         sresult += "I";
    89.         //m_sremembered += "I";
    90.     }
    91.     public void AddChar_J()
    92.     {
    93.         sresult += "J";
    94.         //m_sremembered += "J";
    95.     }
    96.     public void AddChar_K()
    97.     {
    98.         sresult += "K";
    99.         //m_sremembered += "K";
    100.     }
    101.     public void AddChar_L()
    102.     {
    103.         sresult += "L";
    104.         //m_sremembered += "L";
    105.     }
    106.     public void AddChar_M()
    107.     {
    108.         sresult += "M";
    109.         //m_sremembered += "M";
    110.     }
    111.     public void AddChar_N()
    112.     {
    113.         sresult += "N";
    114.         //m_sremembered += "N";
    115.     }
    116.     public void AddChar_O()
    117.     {
    118.         sresult += "O";
    119.         //m_sremembered += "O";
    120.     }
    121.     public void AddChar_P()
    122.     {
    123.         sresult += "P";
    124.         //m_sremembered += "P";
    125.     }
    126.     public void AddChar_Q()
    127.     {
    128.         sresult += "Q";
    129.         //m_sremembered += "Q";
    130.     }
    131.     public void AddChar_R()
    132.     {
    133.         sresult += "R";
    134.         //m_sremembered += "R";
    135.     }
    136.     public void AddChar_S()
    137.     {
    138.         sresult += "S";
    139.         //m_sremembered += "S";
    140.     }
    141.     public void AddChar_T()
    142.     {
    143.         sresult += "T";
    144.         //m_sremembered += "T";
    145.     }
    146.     public void AddChar_U()
    147.     {
    148.         sresult += "U";
    149.         //m_sremembered += "U";
    150.     }
    151.     public void AddChar_V()
    152.     {
    153.         sresult += "V";
    154.         //m_sremembered += "V";
    155.     }
    156.     public void AddChar_W()
    157.     {
    158.         sresult += "W";
    159.         //m_sremembered += "W";
    160.     }
    161.     public void AddChar_X()
    162.     {
    163.         sresult += "X";
    164.         //m_sremembered += "X";
    165.     }
    166.     public void AddChar_Y()
    167.     {
    168.         sresult += "Y";
    169.         //m_sremembered += "Y";
    170.     }
    171.     public void AddChar_Z()
    172.     {
    173.         sresult += "Z";
    174.         //m_sremembered += "Z";
    175.     }
    176.  
    177.     public void DoneGivingChars()
    178.     {
    179.         // Set The LettersToRemIsDone To True
    180.         LettersToRemIsDone = true;
    181.  
    182.         /*if (sresult != null)
    183.         {
    184.             StopCoroutine("ListenForInputSequenceUntilDone");
    185.             sresult = null;
    186.         }*/
    187.     }
    188.  
    189.     // Exp.
    190.     string sresult = "";
    191.     IEnumerator ListenForInputSequenceUntilDone()
    192.     {
    193.         // Wait Time
    194.         yield return new WaitForSeconds(0.5f);
    195.         // Reset Sctring For New inputs
    196.         sresult = "";
    197.         while (true)
    198.         {
    199.             if (LettersToRemIsDone == true) break;
    200.  
    201.             string sval = Input.inputString;
    202.             if (!string.IsNullOrEmpty(sval))
    203.             {
    204.                 sresult += sval;
    205.             }
    206.             yield return null;
    207.         }
    208.         Debug.Log(sresult);
    209.         CharsToRemember[0] = sresult;
    210.         PlayerPrefs.SetString("CharacterToRem", CharsToRemember[0].ToString());
    211.         Debug.Log("Character Saved To Player Prefs");
    212.  
    213.         /*yield return m_wait;
    214.         m_sremembered = "";
    215.  
    216.         while (true)
    217.         {
    218.             string sval = Input.inputString;
    219.  
    220.             if (!string.IsNullOrEmpty(sval))
    221.             {
    222.                 m_sremembered += sval;
    223.             }
    224.  
    225.             yield return null;
    226.         }*/
    227.  
    228.  
    229.     }
    230.  
    231.     /*readonly WaitForSeconds m_wait = new WaitForSeconds(0.5f);
    232.     Coroutine m_remembering;
    233.     string m_sremembered;
    234.     */
    235. }
    236.  
     
    Last edited: Sep 11, 2018
  35. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514
    I added in a method for removing the last character from the input string should it be misunderstood by the VR inputs.

    Code (CSharp):
    1. public void RemoveLastChar()
    2.     {
    3.         sresult = sresult.Substring(0, sresult.Length - 1);
    4.     }
     
  36. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514
    OK So as far as my saving the string in the array for loading back in later what I had to do was this:
    For Saving:
    Code (CSharp):
    1. Debug.Log(sresult);
    2.         CharsToRemember[0] = sresult;
    3.        
    4.         PlayerPrefs.SetString("CharacterToRem", CharsToRemember[0] = sresult);
    5.  
    6.         Debug.Log("Character Saved To Player Prefs");
    For Loading back into the array slot [0] :
    Code (CSharp):
    1. // Load Characters Remembered From Player Prefs To Array Slot 0
    2.         CharsToRemember[0] = PlayerPrefs.GetString("CharacterToRem");
    3.         Debug.Log("Characters Saved Loaded To Array");
     
  37. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514

    Hey Doug,
    Any idea why this might be happening?

    Well I did manage to figure out why my VR inputs were not calling the character calls,
    I had my bool check set to:
    Code (CSharp):
    1. RTM.LettersToRemIsDone == true
    When it should have been:
    Code (CSharp):
    1. RTM.LettersToRemIsDone == false
    in order for the code to be executed.

    Now onto the next weird thing that is happening :confused:

    Seems that when I read in the characters to be saved and then I retrieve the characters it doubles up on each character that was said???
    Not sure why??
    Maybe the coroutine does not get properly stopped??? Although I thought that was what the:
    Code (CSharp):
    1. if (LettersToRemIsDone == true) break;
    Was supposed to do when the bool got changed from here:

    Code (CSharp):
    1. public void DoneGivingChars()
    2.     {
    3.         // Set The LettersToRemIsDone To True
    4.         LettersToRemIsDone = true;
    5.  
    6.     }
    Buuuuuuuuttttt…. Maybe not?? :confused:
     
  38. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    I'm just as surprised as @lordofduct here:


    There should be some information about the integration into an application (or even into Unity). I mean, you said it's going to handle "switch cases" but that appears to be your own way of handling the received input.
    While the technical backend is most-likely completely irrelevant for the programmer, the API you have to speak to is the most important thing. And that's what @lordofduct was asking for. There must be some documentation about how to use the voice recognition SDK properly.

    Looking at the code you provided, it seems you're pretty much trying to hard-code most of the things. The char array, the numbers, all the 'AddChar' methods for every single character. This is (as it is) - with all honesty - not going to scale well.
     
    lordofduct likes this.
  39. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514

    not to worry,
    I got it all figured out,
    It's working perfectly now, turns out that for some reason I had to reboot my computer but now it's all working fine.
    I can ask KITT to remember some initials or characters, he says he's ready and I just read off whatever I want him to remember. And then I can call those back, and have him display those on the screen whenever I want.

    Numerals next ;)

    Oh and for the love of God stop harping on about how the backend VR works. As I had mentioned ONLY how the VR inputs were being handled was the important part.... Jeepers you guys really take the cake sometimes :rolleyes:
     
  40. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Just trying to help out, as it'll be a pain to extend hard-coded stuff. And it simply doesn't look correct.

    For instance, take the recognizers available by Microsoft & Unity for certain platforms, they are very flexible.
    There are multiple types of recognizers: KeywordRecognizers (for explicit commands), DictationRecognizers (for random input, reports current hypothesis, confidence level, errors, semantics ...), PhraseRecognizers and a more complex but quite interesting one, the GrammarRecognizer.

    We've already used some of those on the HoloLens, and I can tell that it appears to be a lot of extra and unnecessary work that you're doing here, when you miss the chance to know the API of the SDK.

    In case you're using different ones, you should check what's available to you in order to make your life easier, to shorten your code and have a more flexible solution to the core problem.
     
    Last edited: Sep 13, 2018
  41. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514
    Thanks,
    Yeah I get that
    But I did not design the back end VR stuff. After it was designed I was just basically given the ball and ran with it.
    Everything is hard codded but that's because in order for it to be KITT it has to Use William Daniels voice clips. So although limited in some areas even with using some external voice duplication like Lyrebird we would still need William's permission to use their algorithms.... sadly because in many way I'd like to get KITT where you could say anything to it but with those limitations we are looking at strictly "Scripted" conversation.... that being said it goes layers deep for what it is ;)
     
  42. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,378
    I don't think he knows what an API is.

    ;)

    (gotta love dem emojis!)
     
  43. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514
    Uh yeah, I do for the record.
    By the Gods you must think I'm some sort of jelly brain lol
    Yeah a Jelly Brain who's building his own fully functioning K.I.T.T. Replica with more tricks in it than you can shake a stick at:rolleyes:
     
  44. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,378
    I don't think you're a jelly brain.

    I think you lack any proficiency in communication skills. As well as an unearned surplus in confidence of your ability to program.

    You also seem to exemplify a behaviour I find on forums a lot. Where in you speak about a subject that is unique and personal to yourself in a manner as if everyone listening aught to already know what it is you're talking about.

    Speaking of KITT... why do you need a video game engine to simulate the voice integration and AI of KITT? ... don't answer that, that's rhetorical.
     
    bobisgod234 likes this.
  45. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514
    Whatever
     
  46. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    514
    Sometimes it helps to see things in context, so for those that MAY be interested here is a video that shows the "Save these initials / characters" scenario in actual use with my K.I.T.T. A.I. and graphical user interface that runs on the dual touch screens. Although not featured in this video KITT also has the ability to turn on devices in the car via the Arduino interface which is also being run from the Unity App. By VR we can have KITT change screens to display information like the factoids, play games, activate car functions or pretty much anything else, Using Unity with the VR has pretty much made the possibilities endless.
    Anyways for those that would like to see the video, enjoy :)