Cannot convert String to int
This is the script:
using UnityEngine;
using System;
public class DataTranslator : MonoBehaviour
{
private static string KILL_SYMBOL = "[KILLS]";
private static string DEATHS_SYMBOL = "[DEATHS]";
public static int DataToKills(string data)
{
return int.Parse (DataToValue(data, KILL_SYMBOL));
}
public static int DataToDeaths(string data)
{
return int.Parse (DataToValue(data, DEATHS_SYMBOL));
}
public static int DataToValue(string data, string symbol)
{
string[] pieces = data.Split('/');
foreach (string piece in pieces)
{
if (piece.StartsWith(symbol))
{
return piece.Substring(symbol.Length);
}
}
Debug.LogError(symbol + "not found in" + data);
return "";
}
}
And this are the error:
1) Assets/DataTranslator.cs(17,20): error CS1502: The best overloaded method match for int.Parse(string)' has some invalid arguments 2)Assets/DataTranslator.cs(11,28): error CS1503: Argument
#1' cannot convert int' expression to type
string'
3) Assets/DataTranslator.cs(17,20): error CS1502: The best overloaded method match for int.Parse(string)' has some invalid arguments 4)Assets/DataTranslator.cs(17,27): error CS1503: Argument
#1' cannot convert int' expression to type
string'
5)Assets/DataTranslator.cs(28,30): error CS0029: Cannot implicitly convert type string' to
int'
6) Assets/DataTranslator.cs(33,16): error CS0029: Cannot implicitly convert type string' to
int'
i can't understand where is the error
Answer by HenryStrattonFW · Jan 22, 2017 at 10:28 PM
This is because your return type for DataToValue is an int. but you are returning strings from it, change your return type to string and this should remove the errors.
And it is possible to show more on the code where it is necessary to correct?