How do I change parent variables in inherit scripts without having to do it in a function.

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

I made a script that’s called Item which has a variable called item_name and another called item_sprite and I want to make a potion Item with a different name and different sprite but I want to do it before _ready() function even starts like how you would make a new variable that every function in that script has access to.

:bust_in_silhouette: Reply From: Ninfur

Add a constructor (_init-function) to the Item base class which sets the variables. Then fill in the arguments from the child classes. I believe something like this should work:

    class_name Item
    var item_name

    func _init(p_item_name: String):
        item_name = p_item_name

.

    extends Item
    class_name Potion

    func _init().("Potion"):
        pass