How do I compare instance of a same object?

Get help using Construct 2

Post » Fri Mar 14, 2014 5:43 pm

Hi, How can i compare variable of the same object in different instances.

I have a sprite object with 3 frames, each frame is part of a puzzle. so i generate 3 different sprites and put each one in a different frame (0,1,2)
I need to verify if all the objects are in the right place.

is there a way to do this with out using global variables.
B
9
S
4
Posts: 49
Reputation: 1,239

Post » Fri Mar 14, 2014 5:53 pm

You probably would have to use their UID that their assigned to do that.
B
23
S
4
G
2
Posts: 364
Reputation: 2,392

Post » Fri Mar 14, 2014 10:24 pm

Thanks PhoenixNightly
But if you use UID in a condition it picks the element with UID x, I have 3 elements and there how to get the variable of each specific element and compare if all of those variables have a state.

thanks
B
9
S
4
Posts: 49
Reputation: 1,239

Post » Sun Mar 16, 2014 3:02 pm

Sorry for the late response back. But there is a event that compare the frame of the object and only the instance(s) that it is true for would trigger the event. So if you did:: Lets say you sprite name is 'Puzzle'.
If you set a event that says Puzzle compare animation frame=1 then any puzzle instance who frame is one would enter this event and run whatever actions you need.
B
23
S
4
G
2
Posts: 364
Reputation: 2,392

Post » Mon Mar 17, 2014 1:56 pm

Hi PhoenixNightly, thanks for the answer.
yes and how i can see if all of the puzzle that are on that frame = 1 have a variable in x state.

in code wold be like this

var pieces_with_angle_zero = 0;
for( puzzle_piece in Puzzle) {
if(puzzle_piece.angle == 0){
pieces_with_angle_zero++;
}
}

if(pieces_with_angle_zero == Puzzle.lenght){
// you have complete the game
}

thanks
B
9
S
4
Posts: 49
Reputation: 1,239

Post » Tue Mar 18, 2014 8:37 pm

Image

Use the 'else' so it don't have to process unnecessary tests. So if the frame =0 it won't execute the other comparisons and skip over them.

Might have to use the 'for each' loop
B
23
S
4
G
2
Posts: 364
Reputation: 2,392


Return to How do I....?

Who is online

Users browsing this forum: bluesun66, Kenthria, Malhog, plinkie, Yahoo [Bot] and 1 guest