0 votes

Even though I have selected the Mob scene in the Script Variables under the Inspector tab, I keep getting the error mentioned in the title.

extends Node

export (PackedScene) var mob
var score

func _ready():
    randomize()


# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
#   pass


func game_over():
    $ScoreTimer.stop()
    $MobTimer.stop()

func new_game():
    score = 0
    $Player.start($StartPosition.position)
    $StartTimer.start()


func _on_MobTimer_timeout():
    $MobPath/MobSpawnLocation.offset = randi()
    var mob = Mob.instance() #This is the line that causes the error


func _on_ScoreTimer_timeout():
    score += 1


func _on_StartTimer_timeout():
    $MobTimer.start()
    $ScoreTimer.start()

Would appreciate any tips to help solve this issue.

in Engine by (24 points)

2 Answers

0 votes
Best answer

I found the issue to be resolved when I changed this line:

export (PackedScene) var mob

To this line:

export (PackedScene) var Mob
by (24 points)
+2 votes

you may have selected the Mob scene but you put it in the mob variable
so when you use it you need to use mob

var m = mob.instance()
by (1,667 points)

Upon attempting the solution mentioned above no errors were produced on compilation, although it produced the following warning:

The local variable 'mob' is shadowing an already-defined variable at line 3.

And upon running the compiled game, the following error is produced:

Invalid call. Nonexistent function 'instance' in base 'PathFollow2D'.

which points to the line var m = mob.instance()

I have resolved the issue in the answer I provided.
It was just an issue of case sensitivity, which I hadn't caught.
Thank you for your help.

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.