Hi Fellas,
sorry is this is a dumb question.
Im completely new to godot.
For starters I wanted to create a simple Card game.
I have a Card class and a Stack class which contains an array of cards.
As I want to use both classes / scripts for KinematicBode2D objects, I let them inheret from this class. For the Card class ive modified the _init() function to accept one parameter which is the value of the Card
extends KinematicBody2D
class_name Card
enum Card_values {ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGTH, NINE, TEN, ELEVEN, TWELVE, SKIP_BO}
export(Card_values) var value = Card_values.ONE
# TODO method should only accept card enum
func _init(new_value):
value = new_value
func myinit(new_value):
value = new_value
Ive created a scene for the card containing so I can instance it. The scene consists of a KinematicBody2D whith the card script attached and a Sprite and CollisionShape2D as childs.
When I try to add a new instance of the card scene and change the values of the card via custom function of the card class i get an error which tells me, that the function i try to call would not exists for KinematicBody2D
Nonexistent function 'myinit' in base 'KinematicBody2D'
Also I've noticed the following error
_create_instance: Condition "r_error.error != Variant::CallError::CALL_OK" is true. Returned: nullptr
This is the call of the function
func create_card(new_value):
var card_scene = load("res://src/actors/card.tscn")
var testcard = card_scene.instance()
testcard.set_name("testcard")
testcard.myinit(new_value)
add_child(testcard)
return testcard
#testcard = Card.new(Card.Card_values.SIX)
# Called when the node enters the scene tree for the first time.
func _ready():
var testcard1 = create_card(Card.Card_values.SIX)
export(Card_values) var value = Card_values.ONE
#var value = Card_values.ONE
# TODO method should only accept card enum
func _init(new_value):
value = new_value
Could it be that my error comes from creating a _init fuction which takes values ?
Should I use a custom init function everywhere ?