qbm

  • Aug 18, 2023
  • Joined Aug 5, 2023
  • 0 best answers
  • I started the card scene all over again and I managed to make it work.
    I changed multiple things and I am now using the button $Button.toggle_mode = true and $Button.button_pressed to know the state of the button.
    I also changed mouse.filter parameter on some nodes.

    I'm not sure what was causing the issue in the first place, but it was somehow related to the card scene.

    Thanks for taking the time to help.

    • I see what you mean, I think it's because the breakpoint hit just after the instantiate is called but before the values are set. If I put a breakpoint before the add_child in the main script, before all the card instances are added to the main scene, I can see these values correctly set.
      visible_texture was a bad name for the variable by the way, I changed it to opposite_side_texture.

      I tried anyway to get rid of these 2 variables by changing the set_card_texture just to be sure, but it doesn't seem to have any effect:

      func set_card_texture(texture: Texture = null) -> void:
      	if texture == null:
      		self.texture = back_texture if self.texture == front_texture else front_texture
      	else:
      		self.texture = texture
    • Actually, I forgot to mention you can see the card faces by removing the parameter of set_card_texture like this:
      card.gd

      func _ready() -> void:
      	set_card_texture()

      This way, every card will spawn face up, and you can see they all have their respective front_texture.

      I think it's a general problem with dynamic values in the instantiated scene, but I don't know why.
      I also tried to tick the Local to Scene option for the card script, but it didn't change anything.

      Every card instance is clickable, but it only affects the last added instance. I also tried to put the flip() function in the main script.

      • Hi there,

        As my first project in Godot, I have chosen to make a 2D memory game.
        I would like to propose multiple card sets, and for each of them, let the user choose the number of different cards to play with.

        For now, I'm just trying to display the cards on the board and make them flip when clicked on.
        My problem is related to the card scene I've created. I have put a button in this scene to detect the pressed signal, when the player clicks on a card to flip it.
        When I instantiate this scene multiple times (one instance for each card), whatever card I click on, only one instance is flipped (now it's the first; at some point it was the last; I don't know why).
        I've tried different things, such as:

        • Setting up the signal with code
        • Setting up the signal in the main script instead of the card's one
        • Setting up a custom signal with a parameter to pass the instance reference connect("pressed", flip_card.bind(added_card), but it's always the same reference that is passed

        I don't understand why it doesn't work and how I should write this differently.

        The source code is available here
        There are 3 scripts:

        • main.gd is attached to the main scene
        • card.gd is attached to the card scene
        • card_set.gd is a class that I use to generate a list of cards by looking into the card_sets folder, but I don't think the problem is here