Godot Version
4.4.1
Question
I’m trying to code a card game, and thought I would start with a basic enough concept. I am trying to create a deck of cards, shuffle them, and then set card_list to properly named cards using the dictionaries above. This solution will help out because later, these codes won’t necessarily correlate to regular cards.
I’ve been putting print(“test”) in a couple places (since deleted) to try and find if the code is getting stuck somewhere, but I haven’t seen any part of the code run whatsoever.
The “play” event is just a spacebar press. The label is just a basic label, its the only other thing in the scene.
code:
extends Node2D
var number_dict = {
“1” : “Ace”,
“2” : “Two”,
“3” : “Three”,
“4” : “Four”,
“5” : “Five”,
“6” : “Six”,
“7” : “Seven,”,
“8” : “Eight”,
“9” : “Nine”,
“10” : “Ten”,
“11” : “Jack”,
“12” : “Queen”,
“13” : “King”,
}
var suite_dict = {
“S” : “Spades”,
“H” : “Hearts”,
“D” : “Diamonds”,
“C” : “Clubs”,
}
var card_list: Array[String] =
var suite: String = “S”
var n: int = 0
var c_num: int = 1
var c_defined: Array[String] =
var drawn_card: String = “”
func _ready():
while n < 52:
print(“test1”)
if c_num > 13:
c_num = 1
match suite:
“S”:
suite = “C”
“C”:
suite = “H”
“H”:
suite = “D”
card_list.append(number_dict[str(c_num)] + " of " + suite_dict[suite])
n += 1
c_num += 1
card_list.shuffle()
func _input(event):
if event.is_action_pressed(“play”):
drawn_card = card_list[len(card_list)]
$Label.text = drawn_card
card_list.remove_at(len(card_list))
If any more information is needed for why the code might not be running, please let me know.