Stuck trying to pass a variable from js to cs and execute script

Hey folks. I’ve been hacking away at this for many hours today. Each time I think I’m making progress, I fail. :smile: I’ve been learning to code for a few months now, off and on, as time and work permit, but really a lot more lately. I got some help with this script yesterday and it’s working great.

#pragma strict
public var fileContents : TextAsset;
function Start () {
var mydata = fileContents.text.Split(“\n”[0]);
// pick a random number between 1 and 10
var myrandom = Random.Range(1,100000);
GetComponent(TextMesh).text = mydata[myrandom];
}
function Update () {
var mydata = fileContents.text.Split(“\n”[0]);
// pick a random number between 1 and 10
var myrandom = Random.Range(1,100000);
GetComponent(TextMesh).text = mydata[myrandom];
}

Now, I’m wanting to convert mydata[myrandom] to a string.

After I have that as a string, I want to execute this cs script with the new variable:

TextToSpeechManager.SendTextToSpeech(the new string);

I’ve been watching tutorials, scouring the web, answers, the forums, etc. I’ve learned about the order in which Unity compiles, standard assets folder, etc. I would post my errors, but I’ve tried so many things now (unsuccessfully!) that I think I’ve seen all the errors. lol

Thanks in advance for anyone willing to help me out with this.

  1. mydata[myrandom] is already a string.
  2. Why are you doing Random.Range(1, 100000)? Are you sure your text file has 100,000 lines in it? You’re very likely to get an ArgumentOutOfRange exception from this. Change it to Random.Range(0, myData.Length);
  3. Have you put the TextToSpeechManager cs file in StandardAssets or another folder in which it will compile first?
  4. We really need to see what specific error you’re getting to avoid just making guesses.