I'm having trouble with instancing...

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

Hi, I’m having some trouble instancing for some reason. Basically, what I’m doing is I have a variable that chooses a random number between 1 and 3, and then another variable that is a rounded version of the previous. If the second variable is 1, it will instance scene “x”, if it’s 2, it will instance scene “y”, and if it’s 3, it will instance scene “z”. Whenever I play the scene, and the second variable is 3, it gives an error saying “Invalid call. Nonexistent function ‘instance’ in base ‘PackedScene’.” Whenever the second variable is 1 or 2, nothing happens.
Here is the code:

extends Node2D

var island1 = load("res://procgen/nodes/island1.tscn")
var island2 = load("res://procgen/nodes/island2.tscn")
var island3 = load("res://procgen/nodes/island3.tscn")

var dir = 200

func _ready():
	randomize()
	var choice = rand_range(0, 4)
	var rounded_choice = int(round(choice))
	if rounded_choice > 3:
		rounded_choice = 3
	if rounded_choice < 1:
		rounded_choice = 1
	$Label.text = str(rounded_choice)
	if rounded_choice == 1:
		var i = island1.instance()
		i.position = Vector2(position.x, position.y + dir)
		get_parent().add_child(i)
		get_parent().get_node("Player").position = i.position
	if rounded_choice == 2:
		var i = island2.instance()
		i.position = Vector2(position.x, position.y + dir)
		get_parent().add_child(i)
		get_parent().get_node("Player").position = i.position
	if rounded_choice == 3:
		var i = island3.instace()
		i.position = Vector2(position.x, position.y + dir)
		get_parent().add_child(i)
		get_parent().get_node("Player").position = i.position

anyone have a solution?

:bust_in_silhouette: Reply From: Eric Ellingson

When you try to instance the island3.tscn scene, you have a typo in instance() (missing the second “n”).

Oh… but that still doesn’t explain why the islands aren’t instancing?

ThreeSpark | 2019-07-28 20:57