Having trouble using set_cells_terrain_connect and tilemaps

Godot Version

4.3

Question

I’m following a youtube tutorial for procedural generation with autotile. I’ve created a 2d node (World) with a Tilemap Layer (“Tilemap”) child node.

I’ve attached a script to the world node:

extends Node2D
@onready var tilemap = $Tilemap
const MAP_SIZE = Vector2(128,128)
const LAND_CAP = 0.3
func _ready():
	make_world()

func make_world():
	var noise = FastNoiseLite.new()
	noise.seed = 100 
	var cells = []
	for x in MAP_SIZE.x:
		for y in MAP_SIZE.y:
			var a = noise.get_noise_2d(x, y)
			if a < LAND_CAP:
				cells.append(Vector2(x,y))
	tilemap.set_cells_terrain_connect(0, cells, 0, 0)

But when I try to test it, I get the following error:

Invalid type in function ‘set_cells_terrain_connect’ in base ‘TileMapLayer’. Cannot convert argument 2 from Array to int.

I’ve tried changing Vetctor2 to Vector2i. I’ve also tried initializing the var cells empty array as a Vector2i.

I’d greatly appreciate any help you could offer, thank you!

The first argument should be an array of Vector2i, the second argument should be an integer. You currently have them switched around.

Note that cells should be of type Vector2i, not Vector2.

1 Like

Thank you very much!

Good to see it worked.

If I may be so bold to make a suggestion, you can use static typing in Godot. Example:

var cells : Array[Vector2i] = []

The big advantage to declaring types is that if you try to use a variable where it doesn’t belong, you’ll get a big red bar in your editor with an error message that says where you tried to put the square peg in the round hole. It’s quite useful.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.