Temple of The Roguelike Forums
Development => Programming => Topic started by: Shaggy on October 04, 2009, 03:33:00 AM
-
[vb.net 2008 express]
I'm working on my Random Dungeon Generation. I have this function that returns whether or not a given area of the map is clear or not so that I can add a room there.
Public Function Clear(ByVal Top As Integer, ByVal Left As Integer, ByVal Height As Integer, ByVal Width As Integer) As Boolean
'Returns whether a rectangle is empty
'used to loop through a rectangle of the map array
Dim introw As Integer
Dim intcol As Integer
'set clear to true as default
Clear = True
'if the rectangle goes outside of the aray, then set clear to fals
If Top + Height > 79 Then Clear = False
If Left + Width > 79 Then Clear = False
'check the rectangle, if it has any numbers in it other than 0[blank] or
' 9[buffer to keep rooms from touching] then set it to false
For introw = Top To (Top + Height)
For intcol = Left To (Left + Width)
If Not Map(introw, intcol) = 0 Or 9 Then
Clear = False
End If
Next
Next
End Function
and it always returns false for some reason. I've displayed the map, and even when it checks a chunk that is 100% empty, it returns false. Any reason?
-
This line:
If Not Map(introw, intcol) = 0 Or 9 Then
You are checking:
If (Not Map(introw, intcol) = 0) Or (9) Then
Which is True (9 is true, isn't it? :) )
When you mean:
If Not (Map(introw, intcol) = 0 Or Map(introw, intcol) = 9) Then
-
It looks valid to me, though I'm definitely not a vb.net expert :( The usage of "if not map = 0 or 9" seems a little odd, but this is probably correct syntax for vb. In C, it would be something like if(map!=0&&map!=9), where as it seems to me here to be if(!(map==0||map==9)), which is essentially the same thing. I suspect it might be receiving bad input, such as Top being too high or left+width being too high. Or perhaps top and left being accidentally swapped somewhere along the way. Just guesses, though. Good luck! :D
Edit; after reading the new post, I highly suspect that this if statement is bad. Try what Scautura suggested :)
-
I tried that, but its still failing the clear check 100% of the time
although I think that may have been part of the problem..
and the thing that bugs me most is that once this clear check is fixed my RDG is basically done, other than aesthetics.
-
Maybe a simple thing like that a room of Height 1 checks two tiles? i mean (for left to left+height) should perhaps check only (for left to left+height-1) ?
Edit:
since it fails 100% you should use a debugger.
-
well the room size is a minimum of 5, maximum of 12 [including walls]
let me try that and see if it works...
^scuttles off to poke and prod at VB^
^scuttles back^
well, it's kinda working
it passing the clear checks, but not in a good way, considering they overlap like crazy
and for some reason it's only making rooms to the north. hm
-
I don't know very much about VB, but I would recommend writing some diagnostic code - have it give you a message at exactly what point clear is set to false, and have the message include the values used to get there. It might help figure out what's happening.
A lot of the time with these things the problem doesn't originate in the particular block of code that has a problem, but rather an error elsewhere "presents" itself at that point, making it look like the problem is there.
Anyway, good luck.
-
Surely you can step into it with the debugger.
-
well the room size is a minimum of 5, maximum of 12 [including walls]
let me try that and see if it works...
^scuttles off to poke and prod at VB^
^scuttles back^
well, it's kinda working
it passing the clear checks, but not in a good way, considering they overlap like crazy
and for some reason it's only making rooms to the north. hm
If all the rooms overlap in the top left corner, it could be a sign that width is set to Left, or height to Top, or that width = Left+width, or Top= Top+width. Any number of these variations would quickly start returning 100% false the further you got away from the top left corner. Can you show the function that is calling this function?
I would suspect since you said north instead of north and left that the problem is that height is set to Top+Height, or that top is set to Top+Height. In any case, your problem is probably due to something related to the Height/Top variables, due to the north specific placement of rooms.
To easily debug this function the "old fashioned" way, call some kind of text or dialog output function in the middle of the function that displays all the functions variables. For instance, right after Clear = true, put some kind of "Display_Text("Top = %d Height = %d",Top,Height)". That way your output would notify you of what is going on inside the function so you can pinpoint what is going wrong.