Can someone help me with this , i already fed up of it

FormatException: Input string was not in a correct format.
System.Number.ThrowOverflowOrFormatException (System.Boolean overflow, System.String overflowResourceKey) (at <834b2ded5dad441e8c7a4287897d63c7>:0)
System.Number.ParseInt32 (System.ReadOnlySpan`1[T] value, System.Globalization.NumberStyles styles, System.Globalization.NumberFormatInfo info) (at <834b2ded5dad441e8c7a4287897d63c7>:0)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class GameContoller : MonoBehaviour
{
[SerializeField]
private Sprite bgImage;

public Sprite[] puzzles;

public List<Sprite> gamePuzzles = new List<Sprite>();

public List btns = new List();

private bool firstGuess, secondGuess;

private int countGuesses;
private int countCorrectGuesses;
private int gameGuesses;

private int firstGuessIndex, secondGuessIndex;

private string firstGuessPuzzle, secondGuessPuzzle;

void Awake(){
puzzles = Resources.LoadAll (“Sprites/Fruits”);
}

void Start() {
GetButtons ();
AddListener ();
AddGamePuzzles();
gameGuesses = gamePuzzles.Count / 2;

}

void GetButtons(){
GameObject objects = GameObject.FindGameObjectsWithTag (“PuzzleButton”);

for(int i = 0; i < objects.Length; i++){
    btns.Add(objects[i].GetComponent<Button>());
    btns[i].image.sprite = bgImage;
}

}

void AddGamePuzzles(){
int looper = btns.Count;
int index = 0;

for (int i = 0; i < looper; i++){

    if(index == looper / 2){
        index = 0;
    }

    gamePuzzles.Add(puzzles[index]);

    index++;
}

}

void AddListener(){
foreach (Button btn in btns){
btn.onClick.AddListener( ()=> PickAPuzzle());
}

}
public void PickAPuzzle(){

if (!firstGuess){

    firstGuess = true;

    firstGuessIndex = int.Parse(UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name);

    firstGuessPuzzle = gamePuzzles[firstGuessIndex].name;

    btns[firstGuessIndex].image.sprite = gamePuzzles[firstGuessIndex];


}else if (!secondGuess){

    secondGuess = true;

    secondGuessIndex = int.Parse(UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name);

    secondGuessPuzzle = gamePuzzles[secondGuessIndex].name;

    btns[secondGuessIndex].image.sprite = gamePuzzles[secondGuessIndex];

    countGuesses++;

    StartCoroutine(CheckIfThePuzzleMatch());

}

}
IEnumerator CheckIfThePuzzleMatch(){

yield return new WaitForSeconds (1f);

if (firstGuessPuzzle == secondGuessPuzzle){

    yield return new WaitForSeconds (.5f);

    btns[firstGuessIndex].interactable = false;
    btns[secondGuessIndex].interactable = false;

    btns[firstGuessIndex].image.color = new Color(0, 0, 0, 0);
    btns[secondGuessIndex].image.color = new Color(0, 0, 0, 0);

CheckIfTheGameIsFinished();

}else {

    yield return new WaitForSeconds (.5f);

    btns[firstGuessIndex].image.sprite = bgImage;
    btns[secondGuessIndex].image.sprite = bgImage;
}

yield return new WaitForSeconds (.5f);

firstGuess = secondGuess = false;

}

void CheckIfTheGameIsFinished() {
countCorrectGuesses++;

if(countCorrectGuesses == gameGuesses){
    Debug.Log("Game Finised");
    Debug.Log("It took you"+ countGuesses + "many guess(es) to finish the game");
}

}
}

You’re trying to convert a string that isn’t convertible into an integer.

Most likely it is this line:

secondGuessIndex = int.Parse(UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name);

But you can tell by reading the error and cross checking the line of code.

As to the error, if I said to you, “hey, convert ‘Kurt’ into an integer,” that doesn’t mean anything.

Similarly if I tell you "convert '123 ’ into an integer, that is the same error because of the space at the end. This is a common mistake.

If you expect bad data in your strings, then use int.TryParse(); instead and handle when it is not correctly formatted.

As for that line above, it is WAAAAAAAY too long.

Pull the string you want out into a local variable so you can actually debug it. I guarantee it is not a string that can be converted to an integer.

If you have more than one or two dots (.) in a single statement, you’re just being mean to yourself.

Putting lots of code on one line DOES NOT make it any faster. That’s not how compiled code works.

The longer your lines of code are, the harder they will be for you to understand them.

How to break down hairy lines of code:

http://plbm.com/?p=248

Break it up, practice social distancing in your code, one thing per line please.

“Programming is hard enough without making it harder for ourselves.” - angrypenguin on Unity3D forums

“Combining a bunch of stuff into one line always feels satisfying, but it’s always a PITA to debug.” - StarManta on the Unity3D forums