Variable From a Parent

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

In short, I have a playspace scene. This is where the enemies spawn. It has a variable called “damage” that changes over time. When the player clicks on an enemy, I want that enemy’s “health” variable to go down by the playspace’s “damage” variable. How do I do that?

Could you specify how you have set up your code? Is there a main Node where you store the bulk of your game’s logic? If that is the case, then use the click event to trigger the damage-inflicting function. Your damage variable and the click event listener should be in the same script.

johnygames | 2018-11-11 22:14

:bust_in_silhouette: Reply From: flurick

Note that this will break if you change the hierarchy of your scene.


If you want to avoid that you could use groups as tags,
or custom signals as seen in this docs tutorial combined with global variables called “singletons”.