Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | malkav182 |
I’m trying to make a script in an enemy class to shoot at the player. I’m trying to use signals but the engine is throwing an error:
0:00:08:0202 - Signal 'player_entered' is already connected to given method 'on_player_entered' in that object.
----------
Type:Error
Description: Signal 'player_entered' is already connected to given method 'on_player_entered' in that object.
Time: 0:00:08:0202
C Error: Condition ' s->slot_map.has(target) ' is true. returned: ERR_INVALID_PARAMETER
C Source: core/object.cpp:1413
C Function: connect
When the player enter in an Area2D
around the enemy, it triggers the following code:
func _on_sensor_body_entered(body):
var n = body
$time_shoot.start()
emit_signal("player_entered" , n)
attack(body)
The signal will be connected by the $time_shoot
:
func _on_time_shoot_timeout():
print("I'm here")
self.connect("player_entered" , self , "on_player_entered")
print(str(self.is_connected("player_entered" , self , "on_player_entered")) + " Connected")
func on_player_entered(body):
print("I'm here man")
attack(body)
self.disconnect("player_entered" , self , "on_player_entered")
print(str(self.is_connected("player_entered" , self , "on_player_entered")) + " Disconnected")
Then the attack function runs and the body_exited
signal should stop the timer
func attack(body):
var shoot = pre_shoot.instance()
var angle = $sight.look_at(body.global_position)
shoot.global_position = $sight.global_position
shoot.global_rotation = global_rotation
shoot.dir = Vector2(cos(global_rotation) , sin(global_rotation)).normalized()
get_parent().add_child(shoot)
func _on_sensor_body_exited(body):
$time_shoot.stop()
pass
But by the Output it seems that the connect() is not connecting to on_player_entered
function. Due to the error, I’m trying to disconnect the function, but no lcuk. What I’m missing?