Unsure of why code appears to not be running? No output at least

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.

Hi,

If absolutely no part of your code is executed (nor _ready nor _input), then it’s probably related to your script not being instantiated anywhere in your active scene.
Are you sure there’s a node somewhere with that script attached to it?

1 Like

If you put your code in backticks:

```gdscript
code
code
code
```

It formats much more nicely:

code
code
code

As it stands, it’s hard to see scope in the code you posted.

1 Like

What they said. Also, you haven’t actually told us what you’re doing to test it. Show us a screenshot of your node tree where the script is attached. Tell us what errors you’re getting. You made it sound like the project doesn’t even start - in which case you should be getting error messages in the Output or Debug window. If the game loads but the Spacebar doesn’t work when you press it and you get no error messages, that’s not the question you asked. We cannot read your mind or see what you’re seeing. Telling us everything you’ve tried and and everything you see helps us help you.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.