This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I made a script that's called Item which has a variable called itemname and another called itemsprite 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.

Godot version v3.4.2
in Engine by (51 points)

1 Answer

0 votes

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
by (1,122 points)
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.