How do I get value of instance variable before destroying it?

0 favourites
  • 4 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hey C3 world.

    When I click on the destroy button, it is supposed to do several things including destroying the sprite.

    The sprite, which is a member of the minerals family, has a couple of instance variables that I need before it is deleted. In the screenshot of the code snippet below, what I'm struggling to accomplish is:

    • take the value of Minerals.WorkerAssigned from the sprite and subtract it from a Global Variable "WorkersAssigned"
    • take the value of Minerals.WorkerAssigned from the sprite and subtract a different Global Variable "WorkerBotsAvailable"

    I need those actions to occur only if the sprite's instance variable (workerassigned) is greater than 1. I'm not sure if this is a time to use looping but I thought I would ask.

    Any help/guidance/time you can throw this way will be appreciated. Thanks all!

  • I don't know if this solves your problem, but it looks like both those blocks of code are running on each mouse click.

    The first block (if WorkersAssigned ≥1) sets Minerals.WorkerAssigned to 0. Then the next block checks if Minerals.WorkerAssigned is ≥0, which it was just set to, so it runs as well.

    If that's causing you problems, you could try putting an else statement in that second condition, so it reads "else if WorkersAssigned ≥0". That way the mouse click only checks for ≥1 or ≥0.

    You might also need to pick a specific Minerals object. Right now, your actions are picking a random member of the Minerals family, which could also cause trouble (unless you only have on Minerals object).

    Hope something in there is helpful!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Does the condition met at the first place? Try to put an action (change Build_Block opacity, angle, etc) to see if the condition actually trigger.

  • Hey everyone! Thank you for your insight and suggestions. Ended up being two problems that made me facepalm when I saw them. You all pointed me in the right direction.

    First was that on the events, one of the conditions was set for Variable (equal to or greater than 0) and the other condition was set for Variable (equal to or greater than 1). Well, when the condition was 1, both matched. Ugh. Changed that.

    The other was later down in the coding for which instance was being updated. I didn't have that code in the snapshot so you couldn't have known about it.

    But you're involvement saved me hours and hours of frustration and allowed me instead to fix the coding and move forward.

    Thank you!!!

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