Set_cell Not Working

Godot Version

Godot 4.3

Question

Hello, I’m just starting out in Godot and I’m trying to make a very simple map for a (mostly) text-based game. I’ve got the tiles that I need to lay down defined properly, and everything in the code works except for the set_cell. The code doesn’t generate any errors. When I run the game, the tilemap appears unchanged, even if I place tiles on it before or keep it empty. Here is the code attached to the tilemap:

func _draw_map_tiles():
	var exit_values: Array = rooms[currentRoom]['map']
	var current_exits: Array
	for value in exit_values:
		current_exits.append(value)
	print(current_exits)
	match exit_values:
		["N", "S", "W", "E"]: tileToDraw = Vector2i(2,1)
		["S", "W", "E"]: tileToDraw = Vector2i(2, 0)
		["W", "E"]: tileToDraw = Vector2i(2, 3)
		["E"]: tileToDraw = Vector2i(1, 3)
		["N", "S", "W"]: tileToDraw = Vector2i(3, 1)
		["S", "W"]: tileToDraw = Vector2i(3,0)
		["W"]: tileToDraw = Vector2i(3,3)
		["N", "S"]: tileToDraw = Vector2i(0, 1)
		["S"]: tileToDraw = Vector2i(0, 0)
		["N"]: tileToDraw = Vector2i(0, 2)
		[]: tileToDraw = Vector2i(0, 3)
	print(str(tileToDraw))
	
	set_cell(Vector2i(3, 2), 0, tileToDraw, 0)

Also attached are screenshots that may prove helpful.

Does manual tile drawing work as expected?

What’s the printed value of tileToDraw?

What’s TileMapLayer doing inside a margin container?

1 Like

FWIW, I also thought this was highly unusual.

2 Likes

Yes, it works normally, and tiles drawn by hand appear when the game is run.

It depends on the particular actions in the game, but it always prints the expected and correct value for each action/state.

As for the container, I think I just put it there to make it easier to move around like the other elements on screen. On second thought, there’s not much of a point to it.

Make sure that cell 3,2 is actually inside the screen.

1 Like

Yes, as far as I know, it’s inside. I should have sent a screenshot of the scene. I’ve manually drawn a placeholder tile on 3,2.

Try setting a bunch of random cell coordinates from the script. What happens in that case?

1 Like

Okay, I’ve tried with smaller and larger coordinates, including some outside the screen (I checked around the area with the project camera override) and couldn’t see any tile.

Do you see the cell if you draw it manually and then run the project?

1 Like

Yes; the only tile that isn’t visible is the one that’s supposed to be drawn by the script.

It disappears when you run?

1 Like

Not the manually drawn tile, that one remains normal even when running. The issue is that the tile that the script is supposed to draw never seems to appear.

What happens if you run this:

extends TileMapLayer

func _ready():
	for i in 32:
		for j in 32:
			set_cell(Vector2i(i, j), 0, Vector2i(0, 0))
1 Like

With that code, the whole tilemap (past the origin, nothing in the negative coords) fills with the 0,0 tile of the atlas.

The problem is then with your _draw_map_tiles(). How and when do you call this?

1 Like

It’s called upon a room transition, when the newly entered room must be loaded onto the map. Here is the code when it is called:

func process_action(action):
if currentRoom == null:
currentRoom = ‘room1’
Map.currentRoom = currentRoom
Map.\_draw_map_tiles()
return render_room(rooms\[currentRoom\])

if rooms[currentRoom]['exits'].has(action) == false:
	return 'You cannot go that way.' + "\n"

if rooms[currentRoom]['exits'][action].has('destination') == true:
	currentRoom = rooms[currentRoom]['exits'][action]['destination']
	Map.currentRoom = currentRoom
	Map._draw_map_tiles()

# return the text of the new room
return render_room(rooms[currentRoom])

The rest of the code within _draw_map_tiles() functions correctly, which is confusing to me.

Who and when calls process_action()?

1 Like

It’s called from another script, it happens whenever text is inputted. Here is the code:

func _on_text_submitted(new_text):
	if (new_text.is_empty()):
		return

	self.set_text('')

	var instruction = text_parser.parse(new_text)

	var output_text = ''
	output_text += " > " + new_text + "\n\n"
	output_text += game_data_processor.process_action(instruction)
	output_text += "\n"

	gameText.clear()
	gameText.append_text(output_text)
	gameText.visible_characters = 0

Try to directly set a specific cell from each of those functions and see where it fails.

1 Like

Okay. I tried from the earliest point, _on_text_submitted, and it failed there. It also fails from process_action.
At this point I’d like to say thanks for bearing with me this whole time, it’s a frustrating issue.