Coding Global Background
Coding Global

Javascript help

Archived a year ago
11 messages
2 members
a year ago
Open in Discord
G
IamUndefined
Verified

Hello , i need help please with this function takeDamage(damage) { if (this.energy > 0 && !this.invulnerable) { // Check if the character is alive and not invulnerable this.energy -= damage; // Reduce the energy of the character this.playAnimation(this.IMAGES_HURT); this.updateStatusBar(); // Update the status bar if (this.energy <= 0) { // Check if the character has died this.energy = 0; // Set the energy to 0 this.die(); // Character dies if energy is 0 } else { this.invulnerable = true; // Make the character invulnerable for a short period setTimeout(() => { this.invulnerable = false; // Remove invulnerability after 2 seconds }, 2000); } } else { console.log("Character is dead or invulnerable."); } } I want when the character is hurt, that the statusbar from character is up do date.But he doesn't work. An ideas? What is wrong?

Replies (11)