I'm making a very basic memory / "find pairs" game where the player has to turn two cards and try to get pairs. I've successfully managed to shuffle all the cards in random positions but my issue is that I have no idea how to limit it so that each card is only instantiated twice and not any more or any less. This is how my code looks like right now:

`extends Node2D

var cat = preload("res://Scenes/cat.tscn")
var chick = preload("res://Scenes/chick.tscn")
var fox = preload("res://Scenes/fox.tscn")
var mouse = preload("res://Scenes/mouse.tscn")
var pig = preload("res://Scenes/pig.tscn")
var rabbit = preload("res://Scenes/rabbit.tscn")

var cards = [cat,chick,fox,mouse,pig,rabbit]

func _ready():
	for i in get_child_count():
		var card = cards[randi() % cards.size()].instantiate()
		get_child(i).add_child(card)`

The node tree:

  • xyz replied to this.
  • SCIPIO Instantiate each card exactly twice. Put all instances in an array. Random shuffle the array and just sequentially add them as children.

    SCIPIO Instantiate each card exactly twice. Put all instances in an array. Random shuffle the array and just sequentially add them as children.