How can I pick an IID between two different instance vari...

  • Hello,

    Basic situation: I have an npc sprite with an instance variable (name: function). I can change this variable with buttons on the screen (woodcutters + - and builders + -). This variable decide what kind of unit will be the npc. For example, I have six npc with "idle" inst. variable. I add two "woodcutters" and three "builders" and one unit stay "idle". I can decrease the unit number with the minus button.

    The problem: When I use one of this button, not only the actual unit type reduced, but also to the other type. I try to explain you with this:

    This is my units:

    • W W B B B W // The first two Woodcutters and after three Builder and finally one Woodcutter again.
    • I want to decrease the builders now, so I use the "Builder -" button. What going to happen?
    • This: W W B B B I // I as Idle, this is the basic function.
    • I wanna to get this result: W W B B I W // As I don't need three builder I have to reduce on two, but I can't isolate only the builders.

    I don't know how pick a value between the builders without the woodcutters. First I have to isolate the builders and after I need to pick a value between the three builders and give this number (IID?) to a global variable. I tried a lot of solution but a always I got something problem. I tried every "pick" condition. Actually I don't know what should I do more. Any idea?

  • I'm sorry, I don't understand some of what your asking for... but should help...

    Why not just use a "for each" then compare the instance variable?

  • Thank you for your answer! With your help I could to do it. I tried the "for each" but it didn't work properly in my situation, but therefore I learned the properly use of compare instance function. So, the solution very easy now:

    Conditions:

    • On left button clicked on Builder decrease icon (minus button)
    • NPC Compare instance variable: NPC; "function" equal to "builder"
    • Pick a random NPC instance

    Action:

    • NPC Instance variable: Set value "function" to "idle"

    Finish. Now when I want to reduce only the amount of Builders (or other units) I can do it perfectly.

    Previously, my problem was that when I want to reduce this ones, not just the type of selected units amount were decreasing (now: Builders) instead, the other ones as well (for example: Woodcutters amount too).

    Anyway, now working properly!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Glad to hear it

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