Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Bug Error Input string was not in a correct format.

Discussion in 'Scripting' started by ALidskiy, Oct 12, 2023.

  1. ALidskiy

    ALidskiy

    Joined:
    Jun 27, 2023
    Posts:
    4
    Hello! My code is responsible for clicks, I click on a button and a cross or zero (tic-tac-toe) appears in this place, but I get an error:



    FormatException: Input string was not in a correct format.
    System.Number.ThrowOverflowOrFormatException (System.Boolean overflow, System.String overflowResourceKey) (at <1f66344f2f89470293d8b67d71308c07>:0)
    System.Number.ParseInt32 (System.ReadOnlySpan`1[T] value, System.Globalization.NumberStyles styles, System.Globalization.NumberFormatInfo info) (at <1f66344f2f89470293d8b67d71308c07>:0)
    System.Int32.Parse (System.String s) (at <1f66344f2f89470293d8b67d71308c07>:0)
    ClickLogicMedium6x6.OnMouseDown () (at Assets/Scripts/XO/ClickLogicMedium6x6.cs:19)
    UnityEngine.SendMouseEvents: DoSendMouseEvents(Int32)




    Код

     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,761
    Note that you posted a Scripting question on the Unity Hub forum. The Unity Hub forum is unsurprisingly about the Unity Hub itself.

    I'll move your post to the scripting forum for you and remove the pointless poll.

    Finally, here's how to post code on the forums: https://forum.unity.com/threads/using-code-tags-properly.143875/
     
  3. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,200
    When you call int.Parse(someString) it expects that someString should be something that can be converted to an int. So, whatever name is, it needs to be able to become an int. If it can't, you get that error. While you could use TryParse before you try to use it, that may or may not solve your problem depending on how important it is that you actually get that int each time.