How can I delete all objects with matching instance variables?

0 favourites
  • 5 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • I'm trying to figure out functional code for my students game.

    My goal is to eventually create a game where I can click on a fruit, and a for loop can check through each fruit adjacent, and determine whether or not it matches.

    If it matches, and there are more than 2 matching fruit in a chain, then destroy all fruits that are in the chain.

    What I'm trying so far, is to manually select fruit and check if all fruit in that selection match. If they do match, and they are right clicked, delete all the matching fruit. How would I manage just this?

  • Adjacent as in all cardinal directions? Or only in a line, like a match 3(+).

    If it's in all directions, you're going to want a simple flood fill. freecodecamp.org/news/flood-fill-algorithm-explained

    Instead of colors, you're going to set an instance variable, as you have done, to mark for deletion. At the end, you can compare the pickedcount for any objects with matching=true to see if its greater than 2, then delete them. Else, reset all matching to false.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm really sorry to ask this so bluntly, but how would I actually implement this code?

    I"ve been trying for the past hour to just get something resembling and I genuinely feel like I'm just not aware enough of construct syntax to get it going.

    What I currently have is a system where I've tried to replicate the exercise best I can as you described, but everything gets deleted, as opposed to just the objects of a set type.

  • Here's an example, I tried to simplify it as much as possible. Sorry the previous reference I linked wasn't in Construct terms - in Construct the "return" parts are handled by conditions, basically if the conditions are not met, then do nothing. dropbox.com/s/6eduutskd8lif24/floodfillexample.c3p

    On clicked object - mark the object for deletion, and check the four adjacent positions to see if it is the same type of object and not already marked, then repeat for each. If it is not the same type or if it is already marked, then nothing happens.

    Afterwards, pick all marked objects. If the total picked is more than two, delete them. Otherwise, clear the marked status.

  • I'm in love with this example. Thank you so so so much for helping me out with this. It's so much more clear now, and it's crazy to see how many fewer lines of code it needed. It's cool to see you even included a randomizer for different frames.

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