I'm trying to convert a High Score tutorial from Javascript to C#. I've managed to convert all of the functions successfully, save for this one. So far I've gone from this:
function EnterHighScore (score : float)
{
// Setup the highscore table text
SetupHighscoreTableText ();
// Insert the entry, it might get rejected if the score is not high enough
var entryIndex = InsertEntry (score);
if (entryIndex == -1)
return;
// Check for the last name the user entered and reuse it
var inputName = PlayerPrefs.GetString ("LastHighscoreName");
while (true)
{
for (var c : char in Input.inputString)
{
// Backspace - Remove the last character
if (c == "\b"[0])
{
if (inputName.Length != 0)
inputName = inputName.Substring(0, inputName.Length - 1);
}
// End of entry.
else if (c == "
"[0])
{
// But the user must have at least entered something
if (inputName.Length)
{
ChangeName (entryIndex, inputName);
SaveEntries ();
// Store the name the user entered as the last high score name,
// so next time the user doesnt have to enter it again
PlayerPrefs.SetString ("LastHighscoreName", inputName);
return;
}
}
// Normal text - just append
else
{
inputName += c;
}
}
// Make sure the name doesnt grow above max entry length
if (inputName.Length > maxNameLength)
inputName = inputName.Substring (0, maxNameLength);
// Add a "." as a blinking text marker.
// Show the "." every .5 seconds
blinkingName = inputName;
var time = Mathf.Repeat (Time.time, 1.0);
if (time > .5)
blinkingName = inputName + ".";
else
blinkingName = inputName;
// Change the name
ChangeName (entryIndex, blinkingName);
yield;
}
}
to this:
void EnterHighScore (float score)
{
// Setup the highscore table text
SetupHighscoreTableText();
// Insert the entry, it might get rejected if the score is not high enough
var entryIndex = InsertEntry (score);
if (entryIndex == -1)
return;
// Check for the last name the user entered and reuse it
string inputName = PlayerPrefs.GetString("LastHighscoreName");
while (true)
{
foreach (char c in Input.inputString)
{
// Backspace - Remove the last character
if (c == "\b"[0])
{
if (inputName.Length != 0)
inputName = inputName.Substring(0, inputName.Length - 1);
}
// End of entry.
else if (c == "
"[0])
{
// But the user must have at least entered something
if (inputName.Length)
{
ChangeName (entryIndex, inputName);
SaveEntries ();
// Store the name the user entered as the last high score name,
// so next time the user doesnt have to enter it again
PlayerPrefs.SetString ("LastHighscoreName", inputName);
return;
}
}
// Normal text - just append
else
{
inputName += c;
}
}
// Make sure the name doesnt grow above max entry length
if (inputName.Length > maxNameLength)
inputName = inputName.Substring (0, maxNameLength);
// Add a "." as a blinking text marker.
// Show the "." every .5 seconds
blinkingName = inputName;
int time = Mathf.Repeat (Time.time, 1.0);
if (time > .5)
blinkingName = inputName + ".";
else
blinkingName = inputName;
// Change the name
ChangeName(entryIndex, blinkingName);
yield;
}
}
At the line where it says "yield;", I get this error: "Only assignment, call, increment, decrement, and new object expressions can be used as a statement." What am I supposed to change it to?
And how do I convert this line to C#:
var entryIndex = InsertEntry (score);
Also, if you notice any more C# errors in the latter code, I'd appreciate any corrections!! Very much so!!!! ;)