0 votes

Hi all,

I am currently creating an array like so:

func createDeck():
    var cardFaces = []
    var suits = ["Hearts", "Diamonds", "Clubs", "Spades"]
    var royals = ["J", "Q", "K", "A"]

    #add numbers 2 to 10 and convert them to string
    for i in range(2,11):
        cardFaces.append(str(i))

    #add the royals
    for j in range(4):
        cardFaces.append(royals[j])

    #let's make the faces and finalise the deck
    for k in range(4):
        for l in range(13):
            var card = (suits[k]+cardFaces[l])
            globals.deck.append(card)

It works well, it creates 52 items in an array, each named similar to :

Hearts2
Hearts3
Hearts4
Hearts5
Hearts6
Hearts7
Hearts8
Hearts9
Hearts10
HeartsJ
HeartsQ
HeartsK
HeartsA
Diamonds2
Diamonds3
Diamonds4
Diamonds5
Diamonds6
Diamonds7
Diamonds8
Diamonds9
Diamonds10
DiamondsJ
DiamondsQ
DiamondsK
DiamondsA
Clubs2
Clubs3
Clubs4
Clubs5
Clubs6
Clubs7
Clubs8
Clubs9
Clubs10
ClubsJ
ClubsQ
ClubsK
ClubsA
Spades2
Spades3
Spades4
Spades5
Spades6
Spades7
Spades8
Spades9
Spades10
SpadesJ
SpadesQ
SpadesK
SpadesA

What I want though, is to create something like:

Hearts, 2, Red
Hearts, 3, Red
etc

I guess it's 52 lists in a list? I'm not too good at this kind of thing but getting there. How can I go about making a list like that with the above info?

Thanks so much.

in Projects by (810 points)

1 Answer

0 votes
Best answer

Got it.

func createDeck():
    var cardFaces = []
    var suits = ["Hearts", "Diamonds", "Clubs", "Spades"]
    var royals = ["J", "Q", "K", "A"]

    #add numbers 2 to 10 and convert them to string
    for i in range(2,11):
        cardFaces.append(str(i))

    #add the royals
    for j in range(4):
        cardFaces.append(royals[j])

    #let's make the faces and finalise the deck
    for k in range(4):
        for l in range(13):
            var card = [suits[k],cardFaces[l]]   #THIS LINE IS THE ONE
            globals.deck.append(card)
by (810 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 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.

Categories