0 votes

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/tower_1_race_1_projectile.gd")

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 !

in Engine by (184 points)

1 Answer

+1 vote

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!

by (10,608 points)

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.

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

thank you for your answer

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.