# Race Standings Help.

**URL:** <https://discussions.unity.com/t/race-standings-help/603855>\
**Category:** C# & .NET\
**Tags:** Scripting\
**Created:** [November 2, 2015, 6:49pm UTC](https://discussions.unity.com/t/race-standings-help/603855 "2015-11-02T18:49:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![TaleOf4Gamers1](https://avatars.discourse-cdn.com/v4/letter/t/c77e96/32.png) [@TaleOf4Gamers1](https://discussions.unity.com/u/TaleOf4Gamers1)\
**Post date:** [November 2, 2015, 6:49pm UTC](https://discussions.unity.com/t/race-standings-help/603855/1 "2015-11-02T18:49:39Z")

</div>

Hey everyone,  
I am starting to feel like a liability on this forum but this issue is such a big one for me and I just cant overcome it. I am trying to make it so that you can see your standing during the race, 1st, 2nd ect but I just cannot write it.  
I came across an old thread: [Logic on calculating positions in a race. - Questions & Answers - Unity Discussions](http://answers.unity3d.com/questions/462034/logic-on-calculating-positions-in-a-race.html) of which I followed the answer but it gives the error, Input string was not in the correct format. I had a quick scout on Google but could not find the specific issue for this. If anyone could help that would be great.

Full error:  
FormatException: Input string was not in the correct format  
System.Int32.Parse (System.String s) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/Int32.cs:629)  
System.Convert.ToInt32 (System.String value) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/Convert.cs:1270)  
Car.OnTriggerEnter (UnityEngine.Collider other) (at Assets/My Scripts/Car.cs:20)

The Code, this script is put on each car and everything is tagged correctly (“1” for the first waypoint, “2” for the second etc) but when I pass a trigger that is when it spams the Input string was not in the correct format error.

```csharp
using UnityEngine;
using System.Collections;

public class Car : MonoBehaviour {
    public int currentWaypoint;
    public int currentLap;
    public Transform lastWaypoint;
   
    private static int WAYPOINT_VALUE = 100;
    private static int LAP_VALUE = 10000;
   
    // Use this for initialization
    public void Initialize() {
        currentWaypoint = 0;
        currentLap = 0;
    }
   
    public void OnTriggerEnter(Collider other) {
        string otherTag = other.gameObject.tag;
        currentWaypoint = System.Convert.ToInt32(otherTag);
        if (currentWaypoint == 1) // completed a lap, so increase currentLap;
            currentLap++;
        lastWaypoint = other.transform;
    }
   
    public float GetDistance() {
        return (transform.position - lastWaypoint.position).magnitude + currentWaypoint * WAYPOINT_VALUE + currentLap * LAP_VALUE;
    }
   
    public int GetCarPosition(Car[] allCars) {
        float distance = GetDistance();
        int position = 1;
        foreach (Car car in allCars) {
            if (car.GetDistance() > distance)
                position++;
        }
        return position;
    }
}

```

This code goes on the \_RaceManager gameobject and I put each car into the carObjects array as instructed.

```csharp
using UnityEngine;
using System.Collections;

public class RaceManager : MonoBehaviour {
    public GameObject[] carObjects;
    public Car[] allCars;
    public Car[] carOrder;
   
    public void Start() {
        // set up the car objects
        allCars = new Car[carObjects.Length];
        carOrder = new Car[carObjects.Length];
        for (int i = 0; i < carObjects.Length; i++) {
            allCars[i] = carObjects[i].GetComponent<Car>();
        }
    }
   
    // this gets called every frame
    public void update() {
        foreach (Car car in allCars) {
            carOrder[car.GetCarPosition(allCars) - 1] = car;
        }
    }
}

```

Thanks in advance and I am so sorry if I sound stupid as this problem (making a race position script) has been probably my worst experience with Coding yet.

---

<div class="post-metadata">

**Author:** ![Fire\_Cube](https://avatars.discourse-cdn.com/v4/letter/f/3e96dc/32.png) [@Fire\_Cube](https://discussions.unity.com/u/Fire_Cube)\
**Post date:** [November 2, 2015, 7:45pm UTC](https://discussions.unity.com/t/race-standings-help/603855/2 "2015-11-02T19:45:07Z")

</div>

The error seams to come from the conversion from string to int. personnaly, i prefer using int.parse(string). It may not be the solution, but it may be enough 🙂

---

<div class="post-metadata">

**Author:** ![TaleOf4Gamers1](https://avatars.discourse-cdn.com/v4/letter/t/c77e96/32.png) [@TaleOf4Gamers1](https://discussions.unity.com/u/TaleOf4Gamers1)\
**Post date:** [November 2, 2015, 8:23pm UTC](https://discussions.unity.com/t/race-standings-help/603855/3 "2015-11-02T20:23:59Z")

</div>

> [@Fire\_Cube](#):
>
> The error seams to come from the conversion from string to int. personnaly, i prefer using int.parse(string). It may not be the solution, but it may be enough 🙂

Thanks, I will try it out.

---

<div class="post-metadata">

**Author:** ![TaleOf4Gamers1](https://avatars.discourse-cdn.com/v4/letter/t/c77e96/32.png) [@TaleOf4Gamers1](https://discussions.unity.com/u/TaleOf4Gamers1)\
**Post date:** [November 3, 2015, 5:51pm UTC](https://discussions.unity.com/t/race-standings-help/603855/4 "2015-11-03T17:51:34Z")

</div>

Ok, I fixed the error it was wrongly names tag.  
Now that it is fixed I have another issue. I dont know how to view the car’s position either by Debug Logging or by putting it on a text object. Any help with getting me to display the positions would be great!

---

<div class="post-metadata">

**Author:** ![SomeGuy22](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/someguy22/32/480372_2.png) [@SomeGuy22](https://discussions.unity.com/u/SomeGuy22)\
**Post date:** [November 3, 2015, 10:29pm UTC](https://discussions.unity.com/t/race-standings-help/603855/5 "2015-11-03T22:29:14Z")

</div>

> [@TaleOf4Gamers\_1](#):
>
> I dont know how to view the car’s position either by Debug Logging or by putting it on a text object. Any help with getting me to display the positions would be great!

```csharp
Debug.Log(gameObject.name + ": " + transform.position);

```

Putting that on each object will log the name and the position. As for the text object, same proecure-- [TextMesh.text](http://docs.unity3d.com/ScriptReference/TextMesh.html) will help. Though in some cases you may need to [convert the Vector3 into a string](http://answers.unity3d.com/questions/167622/vector3tostring.html).
