Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | mehmet432 |
First of all, im a beginner so please explain to me like im a 10 year old.
I have difficulty settings that define CardCount like this,
func _on_Easy_toggled(button_pressed):
var CardCount = 30
func _on_Medium_toggled(button_pressed):
var CardCount = 45
func _on_Hard_toggled(button_pressed):
var CardCount = 60
after the difficulty is selected, i want it to draw “CardCount” amount of cards from res://cards/BaseCards, res://cards/DLC1… and so on that might be added by other players and place them on the next scene.
1st, i tried using arrays but couldn’t understand how to point it to file directories.
2nd, i tried a code i found here, https://forum.godotengine.org/38081/select-random-node2d-from-library-using-data-from-json-file
func get_all_files(path):
#get all the files you have
var files = []
var dir = Directory.new()
dir.open(path)
dir.list_dir_begin()
while true:
var file = dir.get_next()
if file == "":
break
elif not file.begins_with("."):
files.append(file)
dir.list_dir_end()
return files
func create_list():
#create a list containing actual instances
var files = get_all_files("res://cards/")
var sprites = []
for file in files:
sprites.append(load(file).instance())
return sprites
but i don’t know how to get the output from this and place them and i don’t think it scans sub-directories.