Why is my class not referencing

Godot Version

4.2x

Question

So I have this class_named (the_main_node)
and im trying to reference it in another script and its not working its giving me the error "
Error at (16, 22): Identifier "the_main_node" not declared in the current scope.

"

I dont know what do do I need help. The discord and didn’t fined a solution

also I cant put media in the topic bc im a new user so i will be using google drive

i dont think you supposed to reference a Node2D like that
try just load the node2d first, instantiate it, and add child it to something, then pass around the instantiated variable like what you want here

if you really want to try to instantiate by Class Name, try @onready var

You have two solutions based on whether the RigidBody2d (dragable plants) is inside the SceneTree when you start the game or if it’s added to the SceneTree after the game is run.

  • If the RigidBody2d exists on runtime, then you can create an @export variable for your root node (in your case it’s called “the_main_node”)
    • change your the_main_node2 to this:
      @export var the_main_node2: the_main_node
    • open up your main SceneTree, click on your RigidBody2d, assign the exported variable to be your root node
  • If your RigidBody2d is added after runtime, write a method that you call after instantiating the object
    • add the following method to your RigidBody2d script
func _example_init(the_main_node) -> void:
   the_main_node2 = the_main_node
  • change your the_main_node2 to this:
    var the_main_node2: the_main_node

Also please spend some time proofreading as I found some typos:

  • Monster Feeder
  • Label (Rainlabel, SunLabel)
  • Dragging (Draggable, is_dragging)
  • Consider creating ClassNames with camelCase → TheMainNode
  • change (change_time_numbers)
  • random (money_random)
  • Panel (order panel, money panel, time panel)

thanks

also could this have to do anything with it?
{D20A36FE-26F5-43B0-A3F9-8D007E5BDCF5}

why is the gear icon not shaded in?

Thank you.
Did my steps help to resolve your problem?
What’s the current situation?

1 Like

yes they helped me fined the error code to see what’s happening
and brined up some my typos

1 Like