How do I compare instance of a same object?

0 favourites
  • 6 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • 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.

  • You probably would have to use their UID that their assigned to do that.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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

  • 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.

  • 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

  • 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

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