Can tile's be set by tile name instead of the int value?

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

tilemap.set_cell(x,y,0, true, false)

Here 0 represents my first tile in the tileset.

It would be better if I could pass the name in…
ie: dirt, water, lava, stone

tilemap.set_cell(x,y,“stone”, true, false)

Does anyone know if this is possible?

:bust_in_silhouette: Reply From: DDoop

By calling the find_tile_by_name(String name) function on the TileMap’s TileSet, you can get the index of the tile by name. From the docs. You could write a wrapper function that calls both set_cell() and tile_set.find_tile_by_name("stone") (or whatever string you want to use).

:bust_in_silhouette: Reply From: rakkarage

if you know all the ids (you do) you can make an enum that labels the ids
then not need string
my enum:

enum Tile { # match id in tileSet
	Cliff0, Cliff1
	Banner0, Banner1,
	Furnature, Carpet,
	Fountain, Chest, ChestOpenFull, ChestOpenEmpty, ChestBroke, Loot
	TreeStump, TreeBack, TreeFore,
	EdgeInside,	EdgeInsideCorner,
	EdgeOutsideCorner, EdgeOutside,
	Light,
	Theme0Torch, Theme0WallPlain, Theme0Wall, Theme0Floor, Theme0FloorRoom, Theme0Stair, Theme0Door,
	Theme1Torch, Theme1WallPlain, Theme1Wall, Theme1Floor, Theme1FloorRoom, Theme1Stair, Theme1Door,
	Theme2Torch, Theme2WallPlain, Theme2Wall, Theme2Floor, Theme2FloorRoom, Theme2Stair, Theme2Door,
	Theme3Torch, Theme3WallPlain, Theme3Wall, Theme3Floor, Theme3FloorRoom, Theme3Stair, Theme3Door,
	WaterShallowBack, WaterShallowFore,
	WaterDeepBack, WaterDeepFore,
	WaterShallowBackPurple, WaterShallowForePurple,
	WaterDeepBackPurple, WaterDeepForePurple,
	Rubble,
	OutsideDay, OutsideDayPillar, OutsideDayRubble, OutsideDayStair, OutsideFlower,
	OutsideDayDesert, OutsideDayDoodad, OutsideDayGrassDry, OutsideDayDesertStair, OutsideDayGrassGreen,
	OutsideDayHedge, OutsideDayWall, OutsideDayFloor
	OutsideNight, OutsideNightPillar, OutsideNightRubble, OutsideNightStair,
	OutsideNightDesert, OutsideNightDoodad, OutsideNightGrassDry, OutsideNightDesertStair, OutsideNightGrassGreen,
	OutsideBightHedge, OutsideNightWall, OutsideNightFloor
}

GitHub - rakkarage/SetOrder: Reorder Godot TileSet

and here is a program to set the order of existing tileSet ids which is not possible in editor
if you want to rearrange ids to match enum

rakkarage | 2020-08-02 20:47

Thank you - I’ll explore both answers here.

mattkw80 | 2020-08-02 23:35