seeking a var from a scene, with in a scene ?

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

Hey there !
Hitting a wall on this one.

I’m working on the UI of my game.
And when a player put the mouse on the tower he wishes to build, I’m displaying some informations such as name, description, range, etc…

My issue is with the “dmg” of the tower.
Technically, the tower doesn’t have a DMG, it instance a scene projectile that has a dmg.

in TOWER i have a var MISSILE :

var Missile = load("res://scenes/Race/1/Tower_1/")

In missile i have the var “dmg”
So I know I could simply take missile, and look for it on a second line. It’s just not very clean.
I was wondering if there was any simpler way that comes to your mind ?

Something like :

			get_node("DPS/label").text = str(Tower_1_race_1.Missile.dmg)

Is there such thing ?
Thanks !

:bust_in_silhouette: Reply From: njamster

I’d argue that you approach your problem the wrong way: If you want to display the damage-value of a tower, that should be a property of the tower. And when that tower spawns a missile, it sets the damage-value of the missile:

var damage = 30

func fire_missile():
    var new_missile = load("<PathToMissileScene>").instance()
    new_missile.damage = self.damage

That being said, of course you can do something like this:

get_node("DPS/label").text = str(Tower_1_race_1.Missile.dmg)

Not sure why you’re asking this before trying…? Just make sure that Tower_1_race_1 is a reference to your tower-node and it should work exactly like that!

Weird, I obviously tried before and was getting an index error… That’s why I came in thinking that the “double dot” wouldn’t work.

Tower_1_race_1 is the class of the tower. It contain most infos.

thank you for your answer

quizzcode | 2020-06-10 17:08