I am working on an rpg battle system, and so far the animations/sequencing is working but for some odd reason, the targeted health/variable is not updated after a function (attacking). What am I doing wrong? I just upgraded to Godot 4.
NOTE: I included most of the code for this scene for consistency, but I am pretty sure the _attackCommand()
is where the error lies. B
Basically, when the enemy is damaged, their health bar should be moving, but it's not, because the value isn't. I don't get it - everything else in the function is working. My debug shows its the health that is not changing.
extends Node2D
var _player1health = 100
var _player1maxHP = _player1health
var _player1str = 5
var _player1con = 3
var _player1dex = 5
var _player1int = 3
var _player1wis = 5
var _player1lck = 3
var _enemy1health = 100
var _enemy1maxHP = _enemy1health
var _enemy1str = 3
var _enemy1con = 2
var _enemy1dex = 2
var _enemy1int = 2
var _enemy1wis = 2
var _enemy1lck = 2
@export var _canRetreat : bool = true
@export var _enemy1name : String = "Monster"
var _battleStep : int = 0
var _commandReady : bool = false
var _playerState : int = 0
enum _PLAYER_STATES {IDLE,ATTACK,TECH,BLOCK,RUN,WEAK,DEAD}
func _ready() -> void:
$EnemyHUD/EnemyHealth.max_value = _enemy1health
$PlayerInfoHUD/PlayerHealth.max_value = _player1health
$SystemAlert/SystemLabel.text = str(_enemy1name+" appeared!")
$Command_UI/CommandAnimator.play("RESET")
$TextRolling.play("RESET")
$PlayerSprite.play("idle")
$Enemy1Sprite.play("idle")
$TextRolling.play("open_alert")
$SystemTimer.start(1)
_battleStep+=1
func _process(_delta: float) -> void:
$EnemyHUD/EnemyHealth.value = _enemy1health
$PlayerInfoHUD/PlayerHealth.value = _player1health
func _on_attack_button_pressed() -> void:
if _commandReady:
_playerState = 1
$Command_UI/CommandAnimator.play_backwards("open")
$ActivityAlert/ActivityInfo.text = "YOU ATTACKED!"
$TextRolling.play("action_alert")
_attackCommand(_player1str,_enemy1health,$EnemyDamage,$PlayerSprite/PlayerAnimator)
func _on_system_timer_timeout() -> void:
match _battleStep:
1:
$TextRolling.play_backwards("open_alert")
_battleStep+=1
$SystemTimer.start(0.5)
2:
$TextRolling.play("hp_bar_open")
_battleStep+=1
$SystemTimer.start(0.5)
3:
$Command_UI/CommandAnimator.play("open")
_commandReady = true
func _on_player_sprite_animation_finished() -> void:
if $PlayerSprite.animation == "attack":
$EnemyDamage/EnemyDamageAnimator.play("report")
if $PlayerSprite.animation != "idle":
$PlayerSprite.play("idle")
### pretty sure the problem is here, but what?
func _attackCommand(_stat:int,_health:int,_label:Label,_animator:AnimationPlayer):
$TextRolling.play_backwards("action_alert")
_animator.play("attack")
randomize()
var _d6 = randi_range(0,_stat+1)
var _damage
if _d6 == _stat+1:
_damage = _stat*3
else:
_damage = _d6 + _stat
_label.text = str(_damage)
_health-=_damage ### this is not working?