i want to change a varible that will change for both main scene and and the orignal scene

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ahmedKH

i made this spawner code:`

func _on_spawntime_timeout() -> void:
	var px = rand_range(1000 ,0)
	var py = rand_range(0,1000)
	var loc = Vector2(px,py)
	var e = enemy.instance()
	add_child(e)
	e.position = loc

i want the enemy instance same as enemy scene like if i change the damge from the main scene it will change for both enemy instance and the orginal enemy

func _on_hitbox_body_entered(body: Node) -> void:
	if "bullet" in body.name:
		$enemyhealthbar.value -= dmg

this is the code for the enemy dmg

var dmg = 25
:bust_in_silhouette: Reply From: yanb

Make a setter function for the variable.
When you will need to change the variable value, just call it and it will set dmg variable in all of your instances.

Create a list with all of your instances, then in the setter function for each of the enemies set dmg in each of them.

:bust_in_silhouette: Reply From: EmanuelOzorio

If i understanded your logic, the best way is put the enemies in a array or something and create a logic to set the value in the elements of array. Also you can script a foreach with scene children and identify the enemy by some method with has_method.

If you want a more automatic logic you can create a signal in the main scene that triggers every time that the damange is calculated and connect that signal in the enemies.