Finding matching entry in Array and deleting index

0 favourites
  • 5 posts
From the Asset Store
Match 3 Game Gem Pixel Art work for any kind of Match Games.
  • Hi, I'm new to construct (have only been using it a few days) and have decided to embark on what is probably a far too complicated project for learning with, but oh well, I like the challenge!

    I'm basically trying to build a Hearthstone clone so I can learn the basics of creating a card game like this to make a much more complicated version later. I've found several very useful threads on this forum already that have helped me find a way to create and "shuffle" a deck using an array, then deal out cards to the player and add them to a "hand" using another array and referencing animation frames for the different cards. I've even managed to assign stats to the cards using another array and a .json file.

    What I'm currently having trouble with is removing a card from the players hand when it is played (drag-dropped) I came up with a solution for this, which worked in an initial trial I did in another project file, but in the current project it doesn't seem to be working the same?!

    When the card is generated I'm adding the UID of the sprite to an array using the push back action, and that is working fine, I can see in debug. I then have the following event and action set up

    On: Deck - Drag/Drop-Drop > Call Function CardPlayed

    On: Function - CardPlayed >

    arPlayerHand: For each x element >

    arPlayerHand: Current value = Deck.UID > arPlayerHand Delete index Self.CurX from X axis

    The strangest thing for me is that this was working fine in another project, setup almost identically, but when I copied it over, it doesn't work. I can see that it is calling the function as I added another action to check, but it seems to fail at the "current value=Deck.UID" stage, even though I can see in debug that the UID of the sprite I'm moving is present in the arPlayerHand array at the time.

    Huge thanks in advance if anyone can help shed some light on this.

    Here's my construct file if it helps

    https://drive.google.com/open?id=13nHjP0UpggkOQFW28XajEPb4n9dlUCjc

  • You are off to a great start!

    what is happening is that the drag and drop knows which instance of Deck is being dropped, but in your function "CardPlayed" it has no idea which card was just dropped so it defaults to the first card UID which is not in the player's hand. You need to either pass in the UID of the card dropped as a parameter or set a global variable that contains the UID of the last card played.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • As far as card games go, you can check out my tuts on youtube for a flying start.

    Creating solitaire : youtu.be/E1zqEGLeCyI

    Creating a multiplayer card game : youtu.be/BpnkIL7XvvA

    cheers

  • You are off to a great start!

    what is happening is that the drag and drop knows which instance of Deck is being dropped, but in your function "CardPlayed" it has no idea which card was just dropped so it defaults to the first card UID which is not in the player's hand. You need to either pass in the UID of the card dropped as a parameter or set a global variable that contains the UID of the last card played.

    Thank you!!! This worked, and as soon as I read it, I understood completely... I've even done this already with another function (I obviously did that very late at night and forgot) although I did it with a global variable, I like the idea of using a param instead, I think that would be a bit cleaner.

    And thanks, I couldn't have done any of this without the help of this forum. It seems like a great community and I'm excited to learn more :D

  • As far as card games go, you can check out my tuts on youtube for a flying start.

    Creating solitaire : youtu.be/E1zqEGLeCyI

    Creating a multiplayer card game : youtu.be/BpnkIL7XvvA

    cheers

    Thanks I'll check them out!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)