I keep getting out of bounds when I run the following function on the sdir array. It usually happens on the last line, but occassionally on the line before. In debug trace, it is only showing values assigned to element 0,1,2,3. Any suggestions?
Thanks much,
Local sdir:Int[5]=New Int[5] If R.w > m_x Then R.w = m_x If R.h > m_y Then R.h = m_y 'Work out the difference between the room width and Map width etc spaceX = m_x - R.w spaceY = m_y - R.h 'Choose a random position For the New room newx = Rand(1,spacex - 1) newy = Rand(1,spacey - 1) If RoomOverlaps(newx,newy,R.w,R.h) = False 'Fine: Room can go here R.x = newx R.y = newy Return True Else 'Otherwise, move out in a spiral from this point. 'Choose a random sequence of directions forming a spiral sdir[1] = Rand(1,4) sdir[4] = 1 Select sdir[1] Case r_NORTH,r_SOUTH sdir[2] = Rand(3,4) If sdir[1] = r_NORTH Then sdir[3] = r_SOUTH Else sdir[3] = r_NORTH If sdir[2] = r_EAST Then sdir[4] = r_WEST Else sdir[4] = r_EAST Case r_EAST,r_WEST sdir[2] = Rand(1,2) If sdir[1] = r_EAST Then sdir[3] = r_WEST Else sdir[3] = r_EAST If sdir[2] = r_NORTH Then sdir[4] = r_SOUTH Else sdir[4] = r_NORTH End Select
Thanks much,