I have a scene, “Map.tscn”, made up of a TileMap node. Attached to this node is a script, “Map.gd”. The code inside this script looks something like the following:
extends TileMap
func _init(tiles, width, height):
# etc etc
Basically, I made my own function inside this script to facilitate its initialization, since I expect there to be many more variables that I’ll have to initialize with later on.
Then, in my game, I have some code that does the following:
onready var map_class = preload(“res://Map.tscn”)
func _ready():
# some code to determine tiles, width, height
var new_map = map_class.instance()
new_map._init(tiles,width,height)
I expected that this would create my Map scene with my Map script attached to it and call the _init function I defined in that script. Instead, it crashes and tells me “Invalid call. Nonexistent function ‘_init’ in base ‘TileMap’.”
What am I doing wrong?
If I recall, the base nodes can’t be called in that fashion. It may be better creating a class, and putting the initialization function in there.

