Attempt to call function 'map_to_world' in base 'null instance' on a null instance

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

I’ve been making a simple grid-based movement just for a little project and for some reason no matter how I use map_to_world or world_to_map it keeps giving me this error whenever I give any input. Here is my code:

     ##All extensions and imports that the script needs:
extends Sprite
onready var map = get_node("TileMap")
##All Exported Variables
export var TileSize = 16 ##This is the size of the tileset.
export var MoveAllowance = .25 ## this is the time that the player must wait before the next move is taken.

##All Internal Variables:
var timeDelay = 0
var mapGoal = Vector2(0,0)
var pos = Vector2(0,0) ##This will be where the player is.
var goalPos = Vector2(0,0) ## This is where the player wants to be.

##This will happen Only at the beginning of the game.
func _ready():
	self.position = Vector2(8,0) ## this is an alignment thing. for some reason if it isn't started with (+8,+0) it doesn't line up.
	
##This will happen at every tick of the game.
func _process(delta):
	pos = self.position
	if timeDelay == 0:
		if goalPos.x != 0 || goalPos.y != 0:
			self.position = map.map_to_world(goalPos)
			goalPos.x = 0
			goalPos.y = 0
			timeDelay = 1 ##this can be edited to determine how long the player must wait before moving.
		else:
			getInput()
			timeDelay = 0
	else: 
		timeDelay += -MoveAllowance*delta
		
##getInput Simply loads the next input into the _process function for processing.
func getInput():
	if goalPos.x == 0:
		if Input.is_action_pressed("ui_right"):
			goalPos.x += 1
		elif Input.is_action_pressed("ui_left"): 
			goalPos.x += -1
	if goalPos.y == 0:
		if Input.is_action_pressed("ui_up"):
			goalPos.y += -1
		elif Input.is_action_pressed("ui_down"):

Sorry about how messy it is, I just recently got back into coding. Any help would be appreciated

:bust_in_silhouette: Reply From: Zylann

Godot is telling you the map variable is null. So method calls on it result in this error.
Check the console for errors that happened before that.

onready var map = get_node("TileMap")

I suspect get_node could not find “TileMap”. Nodes are accessed by path, relative to the calling node. If the TileMap is actually parent of your sprite, use get_node(".."), or get_parent().