just found out that the rooms were getting sliced in a way that made the top-left and bottom-right points (that i use to draw the square) go crazy. I was getting a room with leftX 35 and rightX 30 so it was reversed and the loop couldnt iterate.
I was tired so my fault here! (Will leave this here for anyone learning that stumbles on the same problem)
Original Post:
Hey yall
I'm working on a little rogue-like project and today i was creating a bsp tree to make a templeesque zone in the dungeon layout.
The problem is that when I used a nested for loop to dig the area of each room, leaving only the surrounding walls, I got into a problem.
I get only the First room digged and the rest are ignored.
The loop is going like this:
Code: Select all
-- stuff slicing the zone into rooms and storing them in a table
for i = 1, #rooms do
print("Im going through "..i)
print("Width", math.abs(rooms[i].lx - rooms[i].rx))
print("Height", math.abs(rooms[i].ly - rooms[i].ry))
for roomY = rooms[i].ly, rooms[i].ry - 1 do
print("in Y for loop", roomY)
for roomX = rooms[i].lx, rooms[i].rx - 1 do
Map[roomX][roomY].tileType = "floor"
print("in X for loop", roomX)
end
end
end
So I ran into lots of trouble on other dugeon gen codes on my lil journey, but this one is making me mad. I use print() to help debugging and what I got this time is that the loop iterate for the first room properly and then its goes flop. After the first sequence loop It gets only to the Y loop and gets nothing on X one.
The table is Full of rooms, the variables inside the table are acessible in loop (i can print the rooms.lx, etc) and there is no 0 or null value.
This is what I get from the print():
Code: Select all
Zone Points: 1,14 26,29
Zone Type: temple
Rooms Quant 7
Im going through 1
Width 4
Height 4
in Y for loop 14
in X for loop 1
in X for loop 2
in X for loop 3
in X for loop 4
in Y for loop 15
in X for loop 1
in X for loop 2
in X for loop 3
in X for loop 4
in Y for loop 16
in X for loop 1
in X for loop 2
in X for loop 3
in X for loop 4
in Y for loop 17
in X for loop 1
in X for loop 2
in X for loop 3
in X for loop 4
Im going through 2
Width 5
Height 1
Im going through 3
Width 5
Height 1
Im going through 4
Width 1
Height 5
in Y for loop 24
in Y for loop 25
in Y for loop 26
in Y for loop 27
in Y for loop 28
Im going through 5
Width 4
Height 1
Im going through 6
Width 1
Height 4
in Y for loop 19
in Y for loop 20
in Y for loop 21
in Y for loop 22
Im going through 7
Width 3
Height 1
(I'm more or less a noob so i feel It can be lack of important knowledge or im too tired to see something thats obvious in this code...)
Please help
Thanks in advance