This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

So i have some sort of "Deck Selection" screen for a card game where you can just put a folder full of .pngs inside res://cards/ and i want those individual folders to appear as "tickable/toggleable" buttons so the user can choose to include every one of them to the output.

How do i expand upon this ?

var DecksList = Array()

func _ready():
    var AddButton =
    for n in DecksList:

this currently only adds 1 button without a name and not several buttons.
i hope to make it add X amount of buttons where X is the number of stuff in the DecksList, and i want it to name the buttons it adds in order like DecksList[0] and then DecksList[1] and so on automatically.

Godot version 3.5.1
in Engine by (43 points)

1 Answer

+1 vote
Best answer

Hmm surprising this does not throw an error because you continually add the same button.


func _ready():
    for n in DecksList.size():
        var AddButton =
        AddButton.set_name("DecksList[%s]" % [n])
        AddButton.set_text("DecksList[%s]" % [n])
by (6,942 points)
selected by

Is there a way to edit the style of these generated buttons.

The buttons are literally named DecksList[0], DecksList[1]... etc, can i give the respective folders name to these.

also this will be much to ask but can i get button signal outputs from them so i can assign the signals to... you know whether or not that folder is going to be included in the total array of Cards

Yeah there is you can set the style you want then save it or set it up in code

var style =
style.bg_color =
AddButton.set('custom_styles/normal', style)

is DeckList a list of Folder Paths? if so

AddButton.set_name(DecksList[n].get_slice("/", 2))

to set up signals are as follows

func _on_pressed(button):

func _ready():
    for n in DecksList.size():
        var AddButton =
        AddButton.connect("pressed", self, "_on_pressed", [AddButton])

this is the DecksList, i want the buttons to be named as the subdirectory folders like
Button1 = Base Cards
Button2 = Booster Pack 1

This is the output i get when i "print(DecksList)"

var DecksList = [res://cards/., res://cards/.., res://cards/Base Cards, res://cards/Booster Pack 1, res://cards/Booster Pack 2, res://cards/Max Basic Pack, res://cards/Max Booster Pack 1, res://cards/Max Booster Pack 2, res://cards/Max Magic, res://cards/Optimized Cards (Hard)]

also i have noticed a problem just right now that i have 2 "res://cards/." in the array.

i'm using this code to generate it and i assume those 2 will interfere with what i'm trying to do, so how do i remove those, i don't even know why they are generated.

var numCards = 0
var dir =
var DecksList = Array()
var CardsPath = "res://cards/"

func _ready():
    if == OK:
        var file_name = dir.get_next()
        while (file_name != ""):
            if file_name.ends_with(".import"):
            if dir.current_is_dir():
                numCards += 1
            file_name = dir.get_next()

To get the base folder of any path use the following


so the name will be

AddButton.set_name("%s" % DecksList[n].get_base_dir().get_file())

you can fix the double "res://cards" by using



dir.list_dir_begin(true, true)

#to avoid having to use this line
if file_name.ends_with(".import"):

You've been an unbelievable help,


until i saw this, i was using


to fix the problem :D

Been where you are now
Just know that it and you does gets better
And when it does just pay it forward.

Thank you Wakatta, :3

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 Frequently asked questions and 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 [email protected] with your username.