Ok, today i had time to look you code and i found the problem, you’re was doing the timeout signal incorrectly as i said before, but you also was deleting the node before the Timer had time to emit the timeout signal:
func activate_effect():
print(item_type)
var effect = effects[item_type]
match item_type:
ItemType.SPEED:
print(effect["amount"])
player.speed += effect["amount"]
set_timer(effect["duration"], shared_player[0], "speed", -effect["amount"])
print(player.speed)
ItemType.HEALTH:
player.vida_actual += effect["amount"]
player.actualizar_vida()
print(player.vida_actual)
print(player.vida_corazones)
ItemType.STRENGTH:
print(effect["amount"])
shared_cabeza.daño += effect["amount"]
set_timer(effect["duration"], shared_cabeza, "daño", -effect["amount"])
print(shared_cabeza.daño)
ItemType.FIRE_RATE:
print(effect["amount"])
shared_cabeza.fire_rate += effect["amount"]
set_timer(effect["duration"], shared_cabeza, "fire_rate", -effect["amount"])
print(shared_cabeza.fire_rate)
ItemType.HEALTH_MID:
print(player.vida_actual)
player.vida_actual += effect["amount"]
player.actualizar_vida()
print(player.vida_actual)
print(player.vida_corazones)
item_types_available.erase(item_type)
queue_free()
You need to wait the timeout signal before delete the node:
item_types_available.erase(item_type)
# Wrong, if you delete the node now, the timeout signal
# will never be emmited and the effect will keep forever
#queue_free()
# You need to first disable the area detection for avoid the same item
# apply the buff again, also need to do it in the idle step, otherwise
# you can crash you game when export because you're deleting physic related
# node in the physics step, so we use set_deferred
$AreaItem.set_deferred("monitoring", false)
# Also make the node invisible to pass the sensation you already deleted the
# item
visible = false
func revert_effect(target, attribute, value):
if target == shared_player[0]:
match attribute:
"speed":
shared_player[0].speed += value
elif target == shared_cabeza:
match attribute:
"fire_rate":
shared_cabeza.fire_rate += value
"daño":
shared_cabeza.daño += value
# There is the correct moment to delete the node
queue_free()
I recommend you look more the debbuger tab, during the gameplay lot of errors appear about calling unnexistent signals, add physics related node outside idle step, etc. Also i recommend you read more tutorials about Godot 4, this code looks like you’re porting from Godot 3.