Enemy damage based on Player attack var

How do I…

Deal damage to an enemy based off of player attack var?

What is the expected result

instead of selecting a set value like 5 I want the damage delt to be based on a variable created so that it can be altered easily.

What is the actual result

Everything works as it should if I set the value to 5, but the player.attack does not. I’m not sure what i’m doing wrong here.

Related screenshots

Project files (optional)

Insert a minimal game showing your issue in a .zip or .rar.

In the object editor, have you defined the variable Attack on the object Player, and set it to 5?

1 Like

Do you have your player on the scene?
Cause i don’t see any events regarding your player
And if object does not exist on scene then its variable cannot be taken from it since they also do not exist

Like you know i exist
But as long as you don’t have my picture you do not know what is my hair color

1 Like

i’m not completely sure on how are you subtracting points to enemies.probably your health bar is not linked to beetle or viceversa.

You said:
if attack button clicked—>change value of health bar → subtract player.attack…and it looks fine …
then (i never used that extension ) but why to apply again player attack damage to enemies. I mean why not check if thehealth bar is <= 0 then…delete beetle…
isn’t the first action enough…?

just asking…

edit: probably it would mean to link objects and repeat for each enemy

1 Like

You’re complely right! I took out the redundancy. Thanks for bringing that to my attention :slight_smile:

That did the trick! I assumed if it was a global object that there was no need to drag it into the scene. Thank you! :slight_smile:

2 Likes