Weird throw for indexOf with Array
I am developing an application that spawns a world, and there are caves in the world, I am trying to check if there is a cave block(blank area) above specified coordinates which are in my array, I am checking if indexOf(coordinates) are equal to current coordinates - 1 Ycoordinate. Here is my code: (things I am talking about occur in lines 4-14.)
private function checkCave():void
{
if (caveAlready == false)
{
var blockYMinus = (blockY - 1)
var aboveIndex = ""
aboveIndex = i + "," + (blockYMinus)
var caveAbove = ""
caveAbove = caveLocations.indexOf(aboveIndex)
trace(caveAbove)
if (caveAbove == 0)
{
caveAlready = true; trace("LOCATION WITH CAVE ABOVE: " + i + "," + blockY)
}
}
if (caveAlready == false)
{
var caveRandom:Number = Math.round(Math.random() * 2000 + (caveSpace * .5));
if (caveRandom <= 30)
{
Global.vars.cave = true;
caveAlready = true;
}
}
else
{
caveRandom = Math.round(Math.random() * 33);
if (caveRandom <= 30)
{
Global.vars.cave = true;
caveAlready = true;
caveLocations.push(i + "," + blockY);
}
else
{
Global.vars.cave = false;
caveAlready = false;
}
In line 11, I trace the value of caveAbove, which should only be -1 or 0, but in my output, I get these values and many more up into the thousands:
-1
-1
-1
-1
-1
-1
-1
-1
-1
0
LOCATION WITH ABOVE: 36,10
-1
-1
-1
-1
-1
-1
15
30
31
32
33
34
35
36
37
38
39
40.
My main concern is that I only got a throw of 0 once? And cannot seem to get it more than once... I don't know if I am using this indexOf properly, so please point me in the right direction.