yeetyoottoot
i dont understand why sometimes this code works and sometimes i get an infinite loop
void Start()
{
roomCount = Random.Range(3, 7);
for(int i = 0; i < roomCount; i++)
{
horizontalChoice = Random.Range(0, 3);
verticalChoice = Random.Range(0, 3);
if (i > 0)
{
while (true)
{
if (roomsValid[verticalChoice][horizontalChoice] == true && roomsVisited[verticalChoice][horizontalChoice] == false)
{
break;
}
else
{
horizontalChoice = Random.Range(0, 3);
verticalChoice = Random.Range(0, 3);
}
}
}
upCheck = verticalChoice - 1;
downCheck = verticalChoice + 1;
leftCheck = horizontalChoice - 1;
rightCheck = horizontalChoice + 1;
for(int a = 0; a < 3; a++)
{
for (int b = 0; b < 3; b++)
{
roomsValid[a][b] = false;
}
}
if (upCheck > -1)
{
roomsValid[upCheck][horizontalChoice] = true;
}
else if (downCheck < 3)
{
roomsValid[downCheck][horizontalChoice] = true;
}
else if (leftCheck > -1)
{
roomsValid[verticalChoice][leftCheck] = true;
}
else if (rightCheck < 3)
{
roomsValid[verticalChoice][rightCheck] = true;
}
roomsVisited[verticalChoice][horizontalChoice] = true;
roomMatrix[verticalChoice][horizontalChoice] = i;
}
void Start()
{
roomCount = Random.Range(3, 7);
for(int i = 0; i < roomCount; i++)
{
horizontalChoice = Random.Range(0, 3);
verticalChoice = Random.Range(0, 3);
if (i > 0)
{
while (true)
{
if (roomsValid[verticalChoice][horizontalChoice] == true && roomsVisited[verticalChoice][horizontalChoice] == false)
{
break;
}
else
{
horizontalChoice = Random.Range(0, 3);
verticalChoice = Random.Range(0, 3);
}
}
}
upCheck = verticalChoice - 1;
downCheck = verticalChoice + 1;
leftCheck = horizontalChoice - 1;
rightCheck = horizontalChoice + 1;
for(int a = 0; a < 3; a++)
{
for (int b = 0; b < 3; b++)
{
roomsValid[a][b] = false;
}
}
if (upCheck > -1)
{
roomsValid[upCheck][horizontalChoice] = true;
}
else if (downCheck < 3)
{
roomsValid[downCheck][horizontalChoice] = true;
}
else if (leftCheck > -1)
{
roomsValid[verticalChoice][leftCheck] = true;
}
else if (rightCheck < 3)
{
roomsValid[verticalChoice][rightCheck] = true;
}
roomsVisited[verticalChoice][horizontalChoice] = true;
roomMatrix[verticalChoice][horizontalChoice] = i;
}
12 replies