#Overriding a variable from the parent class

1 messages · Page 1 of 1 (latest)

tacit sapphire
#

how can I override a variable or a constant from the parent class?
example of how Id expect that to work:

parent class

class_name a extends Node
const b: int = 1
@export var c: String = "abc"

child class

class_name d extends a
const b: int = 8
@export var c: bool = false
rugged shoal
#

im assuming you are getting errors regarding the use of const, which you should just change to var if you plan to change the value

#

additionally, you could try to change the type of c to Variant so that you dont change the type when you override it

tacit sapphire
#

Im getting an error saying that the constant/variable is already declared in the parent class, it happens when using just a regular var too

rugged shoal
#

you likely need to change the values in _init or _ready then to avoid duplicate declarations

hasty ether
#

You can't redeclare/override variables and even if it were to be a thing it would follow the same rules as overriding methods thus requiring the same types

tacit sapphire
#

Are you sure, ParalaxBackground does that?

#

(without chaning the type, but thats still something)