Changing the variable on a specific sprite

  • I have bushes that spawn up to 3 fruit each. Each position is represented by a different instance variable. When it is 0 there is no fruit, at 1 the bush spawns a flower, and at 2 that flower is destroyed and the bush spawns a fruit.

    The problem I am running in to is when the fruit is picked and I set the variable to 0, it is setting that variable to 0 on all of the bushes and not just the one that spawned the fruit.

    So the question is, "How can I change the variable on the bush that spawned the fruit that was picked without changing it on any of the others?"

  • If your bushes are not too close together, it´s probably easiest to use "pick nearest (bush)" and pick the bush that is closest to the fruit collected.

    Another possibility is to check "if bush is overlapping fruit" when the fruit is collected.

    Both are not that precise but should work in most cases. If you need to be precise, you can add an instance variable to the flower/fruit and store the bushes UID in them. When the fruit is collected, use "pick by UID (bush)"

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you for the help. I ended up storing the UID in the flower/fruit when it spawns and that works well. (I had been storing the IID in them earlier, which wasn't working)

  • I just want to make you aware that you could also use a for each loop and pick the bush object, then put the event inside of that loop. The action will then be segregated to the instance in which the event took place. and it is far more cleaner.

    If you got it working that's all that matters. However, it's a good idea to know all of your options.

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