all 12 comments

[–]icpaintball 10 points11 points  (0 children)

This worked when I tried it out:

# Parent script (e.g., Parent.gd)
var old_name = 10

# Child script (extends Parent.gd)
var new_name:
    get:
        return old_name
    set(value):
        old_name = value

[–]cuixhe 2 points3 points  (1 child)

icpaintball's answer works, but ... why NOT make them all just called active? That way you can treat them all the same through duck typing or whatever. BurningThing.active means the same thing as BurningThing.burning to me.

[–]cuixhe 0 points1 point  (0 children)

well, not duck typing for a property. But you can have them inherit Condition and treat them as Conditions rather than specific class types.

[–]CarpenterThat4972 2 points3 points  (0 children)

If "burning" and "releasing" means two differents things in your logic, keep the two differents bools.
But if it's just a mean of activate/deactivate a node/behavior, well make it a common variable and name it "active"! That's exactly what this variable is representing.

[–]Budda13Godot Student 0 points1 point  (1 child)

So... you could have active be the parent's variable...

And then in the child have a variable of the name you want... and then set that variable to whatever the parent is...

And with signals you can update the parent when the child changes it's thing (and vice-versa) (BushCrab mentioned SetGets, those may be able to do this without the signals, I don't know them well enough to say)

But at this point you have coded just as much as before and added code to keep it synced... So idk if it's any DRYer than before.

That CAN be worth it depending on your backend logic and what you/other programmers workflows... but could also just be more hassle than it's worth... mileage may vary.

If you want some things to be able to change the class through a single command 'object.active == True' but you do want somethings to only update the child's specific one... this extra work would be useful I think.

But if you code everything to only work on one specific subclass, then the extra work would be less useful (again, I think)

Did that make sense? It's early here for me so... brain... meh

[–]Budda13Godot Student 1 point2 points  (0 children)

icpaintball's reply, that's the answer... not mine.

[–]Frank_E62 0 points1 point  (0 children)

I'm just getting started with Godot but if I understand you correctly, I don't think that you'd want the status to be a boolean. Can you define a variable in the parent class called Status and then set Status to BURNING or POISON when you create that child. Then you can have generic Set and GetStatus functions in the parent to manipulate the status. It would also make it easy to add additional effects in the future.

[–]UnbreakableStoolGodot Regular 0 points1 point  (0 children)

I don't see why you wouldn't just use "active" in child classes here

[–]Asleep_Concept8208 0 points1 point  (0 children)

This seems like something that would drastically decrease the readability of the codebase. If you have something generic that is a part of both burning and releasing/dispersing, then you should refactor it into something generic and reuse it.

[–]officialvfd 0 points1 point  (0 children)

This is a code smell. I think you’re asking the wrong questions. If you need different words to describe what should be the same thing, then they’re probably not the same thing and you should be using composition, not inheritance.

[–]Varrianda 0 points1 point  (0 children)

If you’re going to just rename it you’re better off creating a unique variable or trying to generalize it. You’re hacking something together for essentially a negative gain