Spot the Error!

Welcome, folks! It's time for a round of "Spot the Error!"

If you can find the error in the script, you win!

        int e = (int) mapSize.x;
        int g = (int) mapSize.z;

        if (rockHeightmap == null) 
            rockHeightmap = noiseGen.CalculateNoise(e, g);

        while (e <= mapSize.x) {
            while (g <= mapSize.z) {    

                double f = rockHeightmap.GetPixel(e, g).grayscale * steepness;
                f = (int) f;
                GameObject[] cubes;
                cubes = GameObject.FindGameObjectsWithTag ("Cube");
                foreach (GameObject cube in cubes) {
                    int e2 = (int) e;
                    int f2 = (int) f;
                    int g2 = (int) g;
                    if(cube.transform.position == new Vector3(e2,f2,g2)) {
                        Cube other;
                        other = cube.GetComponent<Cube>();
                        other.predetermined = true;
                    }
                }
                g++;
            }
            e++;
        }
    }

On a more serious note, I've spent too long staring at this script. There's an error hidden somewhere, but I can't find it, so I turn it over to the pros to "Spot the Error!".

Thanks! Chad

Most likely it's the check against position - the likelyhood of three floating point numbers being identical to three others is pretty slim

Try something along the lines of

if (Vector3.SqrMagnitude(cube.transform.position, new Vector3(e2,f2,g2))< threshold) {

where threshold is some smallish number, the most appropriate value depending on your dataset

This is actually how == does it, but it look like the threshold value they use is ridiculously small, which may not translate well into real world values with errors