How do I this condition?

Get help using Construct 2

Post » Thu Aug 10, 2017 7:12 pm

Hello, can someone please help me with this?

Example:
I have three instances of the same sprite object on screen, this object has a private variable called "var"
Object 1 var = 10
Object 2 var = 5
Object 3 var = 7

I need to know if there is an on-screen object with var = 4, if it does not exist, then I have to create a sprite object with var = 4

If I make this condition in C2:
If (sprite.var! = 4)
This collects the 3 objects

If I do this:
If (sprite.var == 4)
This does not collect any object and the condition will be false, I will not be able to create the object with var = 4

So how should I do the condition ?.
B
31
S
13
G
21
Posts: 844
Reputation: 14,693

Post » Thu Aug 10, 2017 7:42 pm

Object > Compare instance variable > var .. Equal to .. 4 <--- picks all instances of Object with var= 4
________(no actions)
Else <--- when that previous picklist is empty, parent condition is untrue, so the else runs
_____Create Object somewhere
_____set var to 4
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Aug 10, 2017 8:36 pm

99Instances2Go wrote:Object > Compare instance variable > var .. Equal to .. 4 <--- picks all instances of Object with var= 4
________(no actions)
Else <--- when that previous picklist is empty, parent condition is untrue, so the else runs
_____Create Object somewhere
_____set var to 4


That is valid although it is a strange condition for me but it serves to avoid the use of "for each".

I thought of using for each to check the values one by one and if there is any value 4 then put a local variable to 0 to avoid the creation of the object.

Thanks.
B
31
S
13
G
21
Posts: 844
Reputation: 14,693

Post » Thu Aug 10, 2017 9:44 pm

Also, this works when there are just no instances of 'object'. Your rules apply also in that situation. But you can not compare non existing objects. You would not catch that exception.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 4 guests