How do I check if I have the same value in more than one var

Just started using Construct 2? Post your questions here

Post » Wed Mar 01, 2017 2:47 pm

I have 10 instances with a local variable (quant) and I need to check if two or more variables have a 10 as value (because it is not allowed) and if at least one variable has a 10 as value (it's a necessary condition).
Last edited by Braus on Wed Mar 01, 2017 9:16 pm, edited 1 time in total.
B
4
S
2
Posts: 123
Reputation: 846

Post » Wed Mar 01, 2017 2:58 pm

You can pick objects by a variable....

Pick by comparison - Object.Variable = 10

Then you can use pickedCount to determine how many were picked and compare it.

Object.PickedCount is between values 1 & (#number you chose) ---- Or Object.PickedCount ≥ 1 - if there's no upper limit.

If 0 is picked will return false.
Follow my progress on Twitter
or in this thread Archer Devlog
B
35
S
15
G
17
Posts: 945
Reputation: 12,212

Post » Wed Mar 01, 2017 5:22 pm

Thanks.

I am doing this:

Code: Select all
Pick all Sprite
>> Sprite is active (I am checking if the user clicked in each sprite)
>>>> Pick Sprite where Sprite.quant = 10
>>>>>>Sprite.PickedCount  > 1 (to check if exist more than an instance with 10 value in its variable) => action
>>>>>>Else => action
>> Else => action


But it is not working.
B
4
S
2
Posts: 123
Reputation: 846

Post » Wed Mar 01, 2017 7:10 pm

I changed the script for this:

Code: Select all
Pick all Sprite
Sprite is active
>>>>Pick all Sprite
>>>>Pick Sprite where Sprite.quant = 10
>>>>>>Sprite.PickedCount  >= (greater or equal) 1
>>>>>>>>Sprite.PickedCount  > 1 => action
>>>>>>>>Else => action
>>>>>>Else => action


The problems are:
- I cannot confirm if all the sprites are active. I just can check if all the Sprites are not active (e.g. nothing happens If I have one instance activated)
- I cannot confirm If none of my instances does not have the value 10, only if has 1 or more.
B
4
S
2
Posts: 123
Reputation: 846

Post » Wed Mar 01, 2017 7:33 pm

New Event > Condition > Sprite = active ? (i understand that they all have to be active)
__Sub event > Condition > System > compare 2 values .. First = Sprite.PickedCount .. = ... Second = Sprite.Count
_____Sub condition > Sprite > Compare instance variable > ... variable = quant ... equal to ... 10
__________Sub condition > Condition > System > compare 2 values .. First = Sprite.PickedCount .. > ... 1
________________those actions run when there are more then 1 active sprites with quant = 10
_____Else
__________those actions run when there are NO active sprites with quant = 10
__Else
_____those actions run when not all sprites are active
Else
_____Those actions run if there is not one active sprite
B
33
S
18
G
28
Posts: 2,475
Reputation: 20,914

Post » Wed Mar 01, 2017 8:19 pm

I tried your script but I am still don't getting the result I want.

Just one instance may have 10 as value if not, I need to ask the user choose one of them to set as 10.

I also need to know if the user did not activate all the instances (clicking them). This is the reason that I am checking if all the instances are activated or not.
B
4
S
2
Posts: 123
Reputation: 846

Post » Wed Mar 01, 2017 10:45 pm

B
33
S
18
G
28
Posts: 2,475
Reputation: 20,914

Post » Thu Mar 02, 2017 1:08 pm

I found the error thanks to your example.

Thank you.
B
4
S
2
Posts: 123
Reputation: 846


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest