Identifier "icon" not declared in the current scope

Godot Version

Version 4.1.2


I can’t figure this error out
ERROR: Identifier “icon” not declared in the current scope.
THE SCRIPT: var new_icon = icon.instantiate()

What is icon?

The entire script looks like this

func _input(event):
if event.is_action_pressed(“click”):
var new_icon = icon.instantiate()
new_icon.position =

supposedly if i click new icons will appear

Where is icon declared?

I am a newbie so i don’t really understand

Icon isn’t a Godot class/node so I presume it is something you created? How did you create it?

I am reading this book about GDScript that i got from amazon and then i typed in the script from the book

Since you are calling instantiate() I think icon should be a scene resource. But if you didn’t var icon = load("res://icon.tscn") icon doesn’t exist in the script. This is why it throws the error.

I’ll look into it

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.