0 votes

The problem

I'm trying to make a card game, in which cards are a class and when instancing (e.g Card.new()) I intend to pass a value with _init so that Card.new("Cardname") gives me a card based on the name. Also, I'm new to programming.
The idea is to have a CardDatabase that gets called by a Card Class, so that the specified card is drawn in the board (for now I'm just printing to console instead of this). The Card Class is instanciated by a Hand Class when drawing a Card from a Deck (I just included Hand to make it more easy to test and because I'm still noob). My problem is that when I instance the Card with a parameter it doesn't change the intended variable, as shown below:


const DATA = {
    "TestCard": {
        "Name": "TestCard",
            ["one", 2],


class_name Card
onready var CardDatabase = preload("res://CardDatabase.gd")
var CardName:String
var CardInfo = []

func _init(Name: String):
    CardName = Name

func _ready():

    var CardInfo = [CardDatabase.DATA[CardName].Name,CardDatabase.DATA[CardName].Effects]


    var Card1 = Card.new("TestCard")
    func _ready():

#HERE is the problem, when I run this it returns [] instead of [TestCard,["one",2]]

Thanks in advance

Godot version 3.2.2
in Engine by (15 points)
recategorized by

1 Answer

+1 vote
Best answer

Since your card does not extends Node, you need to move _ready function code to _init (note that Node call _ready after it is added to scene using one of the add_child methods).

by (1,314 points)
selected by
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 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 webmaster@godotengine.org with your username.