Help me with my room generator please!

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JorensM

So I made a room generator function, and it works fine most of the time, but occasionally it will not generate left or top walls.

This is how it normally looks:


This is how it occasionally looks:


enter image description here

I can’t for the time being figure out what is wrong with my code. I try to follow the logic trail but to me it seems that it should be working just fine! The code by default sets the tile to FLOOR, and when the program detects an edge, it replaces it with a wall, but for some reason sometimes it doesn’t work with the left or top walls
Here is my code for the room generator:

func generateRoom(var size, var pos, var enemies):
var tile
for y in range(0, size.y):
	for x in range(0, size.x):
		#Set tile to FLOOR by default.
		tile = tile_id.FLOOR
		#Check if first row
		if(y == 0):
			if(x == 0):
				tile = tile_id.WALL_LEFT
			elif(x == size.x - 1):
				tile = tile_id.WALL_RIGHT
				tile = tile_id.WALL_TOP
		#Check if last row
		elif(y == size.y - 1):
			if(x == 0):
				tile = tile_id.WALL_BOTTOM_CORNER_LEFT
			elif(x == size.x - 1):
				tile = tile_id.WALL_BOTTOM_CORNER_RIGHT
				tile = tile_id.WALL_BOTTOM
		elif(x == 0):
			tile = tile_id.WALL_LEFT
		elif(x == size.x - 1):
			tile = tile_id.WALL_RIGHT
		$TileMap.set_cell(x + pos.x, y + pos.y, tile)

The problem only occurs with left and top walls.

:bust_in_silhouette: Reply From: JorensM


It turns out that the problem wasn’t related to the room generator function at all!

Instead what was wrong was my positioning algorithm that determined the positions for the rooms. Sometimes it would pass float type coordinates to the generator, which are incompatible with the tile coordinates. I solved this by converting the coordinates to int values before passing them to the room generator!