[2d] Fog of war on a top down tile movement

Godot Version

v4.2.1

Question

Hello,
I’m making a maze runner type game using a tile by tile movement and would like to add a “fog of war” that keeps the maze dark except for the parts that where already treaded.

the script I’m using is this:

extends TileMap

var fog_tileset : int = 0

func _ready():

for x in range(int(get_used_rect().size.x)):
for y in range(int(get_used_rect().size.y)):
set_cell(x, y, fog_tileset)

func uncover_area(position: Vector2):

var cell_pos = local_to_map(position)

set_cell(cell_pos.x, cell_pos.y, -1)

I’m getting an error on line 9(Invalid argument for “set_cell()” function: argument 2 should be “Vector2i” but is “int”.)

is there a way to fix this or is there a better way t do this?

Here’s definition of set_cell()

First argument should be the ID of layer you are placing tiles on, and second one should be Vector2i of coordinates (so Vector2i(x, y))).

Since there are layers, you could have maze tiles on one layer, and fog of war on another layer.