Nonexistent function 'set_cellv' in base TileMap

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

I’m having problems migrating from the 3.5 version of the engine to the 4.0 stable. I’ve solved the OpenSimplexNoise issue, but now I’m having problems with the TIleMap class, as set_cellv has been removed and I don’t know how to use set_cell in its place:

func set_tile(width, height):
	for x in width:
		for y in height:
			var pos = Vector2(x, y)
			var alt = altitude[pos]
			var temp = temperature[pos]
			var moist = moisture[pos]
			if alt < 0.2:
				biome[pos] = "ocean"
				tilemap.set_cellv(pos, tiles[random_tile(biome_data,"ocean")])
			elif between(alt, 0.2, 0.25):
				biome[pos] = "beach"
				tilemap.set_cellv(pos, tiles[random_tile(biome_data,"beach")])
			#Other Biomes
			elif between(alt, 0.25, 0.8):
				if between(moist, 0, 0.9) and between(temp, 0, 0.6):
					biome[pos] = "plains"
					tilemap.set_cellv(pos, tiles[random_tile(biome_data,"plains")])
				elif between(moist, 0.4, 0.9) and temp > 0.6:
					biome[pos] = "jungle"
					tilemap.set_cellv(pos, tiles[random_tile(biome_data,"jungle")])
				elif temp > 0.6 and moist < 0.4:
					biome[pos] = "desert"
					tilemap.set_cellv(pos, tiles[random_tile(biome_data,"desert")])
				elif moist >= 0.9:
					biome[pos] = "lake"
					tilemap.set_cellv(pos, tiles[random_tile(biome_data,"lake")])

How can I convert this function that uses set_cellv to set the tiles?

:bust_in_silhouette: Reply From: Kertopher

I’ve been having trouble as well, though I’ve figured out this much.

There is a lot of new parameters involved in set_cell now:

set_cell ( int layer, Vector2i coords, int source_id=-1, Vector2i atlas_coords=Vector2i(-1, -1), int alternative_tile=0 )

With version 4, we have the new concept of layers. You probably want 0 for now.

The coords parameter, that will be your pos variable, but you might need to convert it to a Vector2i rather than a Vector2.

For the rest of the 3 parameters, the easiest way to get them (assuming you’ve set up your tiles already): Select your tile map to open up the new tile map editor. Put your mouse on the tile you’d like and hold it for a second. You’ll see a tooltip pop up with the last bits of information. More than likely your source_id and alternative_id will probably be 0. The atlas_coord should be the position of where your tile is at in your tileset.

Once you change your tiles map to instead point to atlas coords, you can simply do:

So to convert:

tilemap.set_cell(0, pos, 0, tiles[random_file(biome_data, "lake")], 0)

If it fails with the pos, just covert your Vector2 into Vector2i and you should be good.