Errors with _on_body_entered() and _on_body_exited?

Godot Version

4.1.1

Question

I have two scripts that should interact: PickaxeSwing and CollisionManagement. Whenever I press E, the pickaxe should rotate, but stop rotating when it collides with a body from my tilemap. Unfortunately, before implementing this, the pickaxe rotated correctly, but now, it doesn’t even rotate which leads me to believe that my script isn’t even making it to CollisionManagement.

PickaxeSwing:

extends CollisionShape2D

signal pickcollision_ready()

@export var transformation = Transform2D()
@export var rotation_speed = 1000 

@onready var pickcollision
var picksprite

var limb
var rotating = false  # Degrees per step
var total_rotation = 0   # Total rotation so far
var beardy
var tilemap
var small_movement = Vector2(0.1, 0.1)
# Called when the node enters the scene tree for the first time.
func _ready():
	limb = $"."
	limb.visible = false
		# Load the scene containing the TileMap
	var scene = load("res://Scenes/Themine.tscn")
	
	# Instance the scene to access its nodes
	var scene_instance = scene.instantiate()
	
	# Find the TileMap node within the scene
	tilemap = find_tilemap_node(scene_instance)
	
	pickcollision = $"."
	emit_signal("pickcollision_ready")
	pickcollision.set_deferred("disabled", true)

func _process(_delta):
	limb = $".."
	pickcollision = $"."
	transformation.origin = pickcollision.global_position
	##var collide
	# Check for key press
	if Input.is_action_pressed("ui_accept"):
		CollisionManagement
	# Check for key release
	else:
		rotating = false
		pickcollision.set_deferred("disabled", true)
		limb.visible = true
		pickcollision.rotation = 0

func rotate_limb(delta):
	if rotating:
		# Rotate the limb
		limb.rotate(deg_to_rad(rotation_speed) * delta)
		
		# Update total rotation
		total_rotation += rotation_speed
		
		# Check if total rotation reaches 360 degrees
		if total_rotation >= 360:
			total_rotation = 0
			rotating = false

func find_tilemap_node(node):
	# Recursive function to find the TileMap node within the scene
	if node is TileMap:
		return node

func _on_beardycollision_ready():
	beardy = $"../../../CollisionPolygon2D"
	print("beardycollision ready")
	
func _on_picksprite_ready():
	print("picksprite ready")
	picksprite = $"../AnimatedSprite2D3"

CollisionManagement:

extends Area2D

var rotating
var tilemap
@onready var pickcoll
var limb

func _ready():
	var scene = load("res://Scenes/Themine.tscn")
	
	# Instance the scene to access its nodes
	var scene_instance = scene.instantiate()
	
	# Find the TileMap node within the scene
	tilemap = find_tilemap_node(scene_instance)
	print(tilemap)

func _on_pickcollision_ready():
	pickcoll = limb.pickcollision
	
	print(pickcoll)
	
	self.connect("body_entered", _on_body_entered)
	self.connect("body_exited", _on_body_exited)

func find_tilemap_node(node):
	# Recursive function to find the TileMap node within the scene
	if node is TileMap:
		return node

func _on_body_entered(tilemap):
	# Called when the CollisionShape2D enters another physics body
	pickcoll = limb.pickcollision
	print("Collision entered with", tilemap.name)
	rotating = false
	pickcoll.set_deferred("disabled", false)
	limb.visible = true

func _on_body_exited(tilemap, delta):
	# Called when the CollisionShape2D exits another physics body
	limb = PickaxeSwing.limb
	pickcoll = PickaxeSwing.pickcollision
	
	print("Collision exited with", tilemap)
	rotating = true
	pickcoll.set_deferred("disabled", false)
	limb.visible = true;
	PickaxeSwing.rotate_limb(delta)

Errors:
One error said that me calling CollisionManagement in PickaxeSwing was a ‘standalone expression’. I also suspect that I am not calling my tilemap properly.

Thanks for your help!

That is a standalone expression, meaning it doesn’t do anything. I’m not sure what you were trying to do with it. Shouldn’t you just set rotate to true there?

No, because I only want it to rotate if it isn’t in contact with a body? I attempted to call CollisionManagement to check to see if it is in contact with any body, and if not, it should rotate as its set up to do.

You can only call functions, but CollisionManagement is a scene! You need to get the respective node from the tree, then call a function of that node.