0 votes

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?

in Engine by (125 points)

1 Answer

0 votes

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

by (1,656 points)

Oh... but that still doesn't explain why the islands aren't instancing?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.