0 votes

I have an object and when it was hit and has 0 hp I call queue_free() on it. In its script there's the _on_hit(damage) function. In this I increase the weapon's damage for 5 seconds (yield(get_tree().create_timer(5), "timeout") and after the time is out, the damage will be decreased again. But if the object is queue_free()d, it cannot reset the damage. How should I solve this problem?

in Engine by (380 points)

Hi! I'm not sure if im getting right the question, but can't you decrease it manually before calling queue_free?

I can but I don't want to do that. I don't care if the object still exists or not, the damage should be decreased after 5 seconds, not before, not after.

Can you be more descriptive? Is the object a monster? It sounds to me like you are changing the weapon's damage from within a monster object's script, which would make sense if the weapon belonged to the monster, but not if the weapon belongs to the player. Just trying to understand what you're describing.

I also don't understand. So its like when you hit someone, you make the weapon's damage higher for some time? In that case, the timer should be on the weapon, not on the object that got hit. You can start that timer on the weapon as soon as you increase the damage.

It's not a monster, it's a special stone that makes the pickaxe more "dangerous" when hit hahah.

So i would do this way. Make a set_damage(damage) function in your weapon. Inside it you set the damage and start a timer. When the timer times out, set the damaga again to original value. Instead of using yield, i would probably use a Timer node in case you can hit multiple stones at the same time, and you dont want to the damage resets when the first timeout occured.

I concur, sounds like you are describing "feature envy" MaaaxIKing

1 Answer

0 votes

You can use the signal "tree_exiting()" and reset the damage upon receiving it. But you can't change property of already freed object because it exists no more.
Or maybe you should move this property in the parent object or Globals singleton and read the value when creating object and update when it changes.

by (124 points)
edited by

I think he is asking other thing. As he said in the comments, he wants to hit a stone that temporary gives the character's weapon more damage. After a time, he wants to reset that damage. He is reseting the damage of the weapon from the stone, but when the stone is cleared, it doesnt reset it anymore, ofcourse, because it was freed.
Thats why some of us suggested he should reset the damage from the weapon itself, instead of trying to reset it from an object that can be cleared.

p7f already helped me to solve my problem. I want the damage to reset after 5 seconds and not when the stone doesn't exist anymore or at any other time. Just when 5 seconds are over. Thanks to p7f!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.