#Using nested classes
29 messages · Page 1 of 1 (latest)
extends Resource
class_name Card
export var index = 0
export var title = ""
extends Resource
class_name Deck
export var cards = []
func add_card(card):
cards.append(card)
func shuffle():
cards = cards.shuffle()
Up to this point it works
func _ready():
...
deck.add_card(card)
card = Card.new()
#deck.shuffle()
var output = "Card index: %d - %s" % [deck.cards[i].index, deck.cards[i].title]
output += "\n"
output += "Value i: %d Deck total %d" % [i, deck.cards.size()]
print(output)
But when I remove the comment that shuffle function it doesn't work
I must add that I did change the names of the files
I closed and opened the editor but I still have the issue
where is the _ready function located ?
It said Invalid get index '0'
ah
your deck might be empty, try doing it in this order instead
var card = Card.new()
deck.add_card(card)
Yeah I do, I declared the card in the top, before the _ready function but I need to remove the data to get a new card
oh, this code is inside a for loop ?
The deck is also a class that I declared before the ready function and it's in a while loop
It's just to text the waters, make a deck so that I can work with the functionality first before I can add the cards and visuals
ah i missed this, you're assigning the return value of cards.shuffle() to cards
however, the shuffle of Array is a function that doesn't return anything
You mean deck.shuffle()?
you only need to call cards.shuffle() and that's it
no, the shuffle function you're using on the cards Array