Skip to content

normal_bar

Kamran Wali edited this page Dec 2, 2024 · 7 revisions

Inherits: base_bar

Inherited By: normal_bar_values

Description

normal_bar acts like a normal bar which means that adding a value will just add the value and subtracting a value will just subtract it. To use this bar make sure to set the maximum value at the scene start otherwise the default value will be used as maximum which is 1. Optionally you can set the current value as well if you want to at the scene start otherwise its value will be 0.

Tutorials

Methods

Return Type Name
void subtract( int value )

Method Descriptions

void subtract ( int value )

This method subtracts the _value_cur with the given value. While subtracting the _value_cur property will never go below 0. It will stop at 0.

Note: If the parameter value given is less than and equal to 0 then the calculation will be ignored and nothing will happen. Only positive values greater than 0 will be allowed for calculation.


Example

SomeScript.gd

extends Node
@export var bar: COP_BaseBar

func _ready() -> void:
  bar.set_max(10)
  bar.set_current(10) # Optional: If you also want to set the current value at the start but it is NOT necessary if NOT needed

## This method hurts the character with the given value.
func hurt(value: int) -> void:
  bar.subtract(value) # Removing health by subtracting bar's current value

## This method heals the character with the given value.
func heal(value: int) -> void:
  bar.add(value) # Adding health by adding to bar's current value

## This method checks if the character is dead or NOT.
func is_dead() -> bool:
  return is_depleted()

## This method returns the health's normal value so that the UI bar can be synced.
func get_health_normal() -> float:
  return bar.get_normal() # The health's normal value which is the bar's normal value
Clone this wiki locally