How do I use GridMap inside a KinematicBody script?

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

My scene composed of a GridMap and KinematicBody:

- World
  - GridMap
  - KinematicBody (Player)
     - MeshInstance
     - CollisionShape
     - Camera

I would like to check the GridMap cells inside the Player script:

extends KinematicBody

var grid_map

func _ready():
	grid_map = get_node("../GridMap")
	if grid_map.get_cell_item(0, 0, 0) == INVALID_CELL_ITEM:
		print("Empty cell!")

The editor yelds an error Parser Error: The identifier "INVALID_CELL_ITEM" isn't declared in the current scope.

How do I “include” or “import” the GridMap class to allow its use in my script?

:bust_in_silhouette: Reply From: Zylann

INVALID_CELL_ITEM is a constant inside the GridMap class. You need to prefix with the class name to use it:

if grid_map.get_cell_item(0, 0, 0) == GridMap.INVALID_CELL_ITEM:

You can omit the class name only if your script inherits that class.