0 votes

Hi I'm new in Godot and I was trying the tutorial for Dodge the creeps, but it gives me this error Invalid call. Nonexistent function "instance" in base "Pathfollow2D", i already check that the PackedScene is in the inspector, this is the code:

extends Node

export (PackedScene) var Mob
var score

func _ready():

func game_over():

func new_game():
    score = 0
    $HUD.show_message("Get Ready")

func _on_MobTimer_timeout():
    var Mob = Mob.instance()
    var direction = $MobPath/MobSpawnLocation.rotation + PI /2
    direction += rand_range( -PI/4, PI/4)
    Mob.rotation = direction
    Mob.linear_velocity = Vector2(rand_range(Mob.MIN_SPEED, Mob.MAX_SPEED), 0)
    Mob.linear_velocity = Mob.linear_velocity.rotated(direction)

func _on_ScoreTimer_timeout():
    score += 1

func _on_StartTimer_timeout():

the engine tell me that the problem is in this line: var Mob = Mob.instance(), anyone knows what is wrong with the code?

in Engine by (16 points)
edited by

When you do a Mob.instance() you get an instance of the Mob scene returned. So you don't want to overwrite Mob variable. Instead in on_MobTimer try doing var mob = Mob.instance() (lowercase mob). And then in the same function change the Mob to mob everywhere.

Please log in or register to answer this question.

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 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 webmaster@godotengine.org with your username.