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

Get help using Construct 2

Post » Sun Oct 25, 2015 1:34 am

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?
B
5
S
1
Posts: 37
Reputation: 441

Post » Sun Oct 25, 2015 3:45 am

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?
Eat ALL THE BACON!
B
45
S
17
G
3
Posts: 290
Reputation: 4,993

Post » Sun Oct 25, 2015 2:17 pm

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!
B
5
S
1
Posts: 37
Reputation: 441

Post » Mon Oct 26, 2015 12:59 pm

Glad to hear it :D
Eat ALL THE BACON!
B
45
S
17
G
3
Posts: 290
Reputation: 4,993


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 15 guests