Implementing godot 4 code in 3.5

Godot Version

i am using godot 3.5

Question

for a hardware limitaion reasons i am using godot version 3.5;
in order to make souls-like prototype i am using (catprisbery) 3.5 template, i tried using his other template for version 4 as guide line (i like his methode because it reusable and expanble) to implemante new features but i stuck on (health_changed) signal .
the editor gives me an error that the signal isn’t declared in the scope yet it is in the top of script so it should be global to the script i wonder if it is the typing but it is right; plz help i cant figure this out.
thanks.

extends Node

class_name healthSystem

signal health_updated

export var total_heath : int = 5
onready var current_health = total_heath
export node paths
export (NodePath) var hit_reporting_node_path
export (NodePath) var heal_reporting_node_path
export (NodePath) var health_bar_control_path

#exporting strins
export var damage_signal : String = “damage_taken”
export var heal_signal : String = “health_received”

#exporting other types
export var show_time :float = 2
var show_timer : Timer

Declare variables to hold the references to the nodes

var hit_reporting_node: Node
var heal_reporting_node: Node
var health_bar_control: Node

signal died

func _ready():
# Check if the node paths are valid
if hit_reporting_node_path:
# Get the node from the scene tree using the node path
hit_reporting_node = get_node(hit_reporting_node_path)
# Check if the node was successfully retrieved
if hit_reporting_node:
print(“Hit reporting node is:”, hit_reporting_node.name)

if heal_reporting_node_path:
	heal_reporting_node = get_node(heal_reporting_node_path)
	
if health_bar_control_path:
	health_bar_control = get_node(health_bar_control_path)

#other code

if hit_reporting_node:
	if hit_reporting_node.has_signal("damage_signal"):
		hit_reporting_node.connect("damage_signal",self,"_on_damage_signal")

if heal_reporting_node:
	if heal_reporting_node.has_signal(heal_signal):
		heal_reporting_node.connect("heal_signal",self,"_on_health_signal")
	
if health_bar_control:
	health_bar_control.hide()
	show_timer = Timer.new()
	show_timer.one_shot = true
	show_timer.wait_time = show_time
	show_timer.timeout.connect("_on_show_timer_timeout")
	add_child(show_timer)

func _physics_process(_delta):
if show_timer:
if show_timer.time_left:
show_health()

func _on_damage_signal(_by_what):
if health_bar_control:
show_timer.start()
var damage_power = _by_what.power
current_health -= damage_power
health_updated.emit(current_health)
if current_health <= 0:
died.emit()

func show_health():
var current_camera = get_viewport().get_camera_3d()
var screenspace = current_camera.unproject_position(hit_reporting_node.global_position)
health_bar_control.position = screenspace
health_bar_control.show()

Emitting signals in 3.5 is done like so

emit_signal("health_updated", current_health)
1 Like

the error has gone , thanks a lot

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.