How do I reference a sprite within a group with the same name?

0 favourites
  • 7 posts
From the Asset Store
A set of 10 pixel art animated magic effects with icons. 2 Fire, 2 Earth, 2 Wind, 2 Water, Portal, Explosion.
  • Hi All,

    I will appreciate it when you can help me with the following problem:

    I have a group of sprites called "sprOptions". This group contains 4 sprites with options and 1 solution. These are the UID's of the sprites:

    Option A: UID=15

    Option B: UID=16

    Option C: UID=17

    Option D: UID=18

    Solution: UID=19

    From the moment the player clicks an option, the options (A to D) has to be set invisible and the solutions sprite has to be set visible.

    When I set the visibility for sprOptions to invisible, then in a sub-event use "Pick instance with UID 19" and add the action "sprOptions" Set visibility to Visible.

    When I run the layout, everything is invisible. Also for later actions, it is very important to reference each sprite within the sprite group sprOptions.

    I ask myself, is it not better to create 5 sprites, for example:

    sprOption_A

    sprOption_B

    sprOption_C

    sprOption_D

    sprSolution

    It is easier to keep track of, however I use the former structure because I can change the frames at one place for all 5. For example, changing the border from green to blue is just selecting the blue frame for all of them.

    Please, can you tell me what I do wrong and how I properly select each individual sprite by UID.

    Thank you so much!

    Chris

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I don't completely understand what you are trying to do, but I can answer your title question--How do I reference a sprite.

    when you click the sprite put the uid in a variable (call it last_pick). You don't change that value until some other sprite from the group is picked at which point last_pick is the uid of that newly picked sprite. This distinquishes one of five otherwise identical sprites as the sprite last picked.

    How you store last_pick is a separate question, you could use a static variable, a global variable, a dictionary entry etc...

    yours

    winkr7

  • Hello Winkr7,

    Thank you for your reply, which I do appreciate. To give you an idea, please take a look at the following image:

    In the top display area (the blue frame), the question is how. The four green objects in the under section, are the options given of which one is the correct one. Behind the first green object, you see a blue frame. This object is invisible until the player choose an answer. On that moment all four option objects become invisible and the correct answer object, become visible.

    So the player click one of the option sprites (which have all the same name with different UID), the options disappear and the correct answer frame shows up.

    My problem is that cannot access each individual object inside the sprite group. I need to find a way to tell the correct answer to show/hide and the same for each of the four option objects.

    I do appreciate your reply. Thank you again for looking into my problem.

    Kind regards,

    Chris

  • The correct answer will be known before the player chooses, so the green object should already have an instance variable where value 'correct' or 'incorrect' is assigned. When the player chooses an answer, you can make the green objects where value=incorrect invisible. So what i'm saying is you pick by a variable value, not by UID.

    However when I look at your post above, you say that all the green answer objects go invisible anyway, so is there a need to pick one ? Unless you meant that all of them going invisible is just the 'current functionality' and a bug, in which case you can do the above.

  • Hi Ironz,

    Thank you for your reply which I appreciate so much.

    What I want to accomplish and fail is to make the green option objects invisible, while the result object become visible. Whatever I do, they become all visible or invisible.

    Both the options and solution are in the same sprite. I can resolve this problem by putting the options and the resolution in a separate sprite.

    However, that will only partly solve my problem. When the player click an option, for a short time, it needs to show another colour. For that, I need a clear reference to the choosen option.

    On this moment, I changed the structure of the game and created for each option and the solution a separate sprite. However, for a safe future, I need to know how to reference and access each individual option in the same sprite group.

    Until your reply, I didn't think much about an instance variable holding the correct/incorrect result. The correct/incorrect answer is on this moment stored in the database, so a reference between the instance variable and the database is a very good idea.

    Thank you for your information, which I value very much.

    Kind regards,

    Chris

  • So which part is not resolved at the moment ? I think for the second object behind you can just have one instance and set its position to the correct answer ?

  • Hi Lionz,

    Thank you for your reply. I made a reply on Saturday evening, but for some unknown reason, it didn't show up on the forum. Therefore, I create another reply.

    I changed my quiz so that the four options have their own sprite and the solution. So in total, there are five sprites:

    sprOption_A

    sprOption_B

    sprOption_C

    sprOption_D

    sprSolution

    The four sprOption_X sprites have an instant variable blnSolution, as you suggested. The questions/solutions are stored in a JSON file. The values of the json file will set the blnSolution to true for the sprOption sprite which is correct.

    It was my intention to reference each member in the sprOption sprite (4 members) by UID. Regretfully that didn't workout as expected. But the solution now, is also fine.

    Thank you again for your help. I wish you all the best.

    Kind Regards,

    Chris

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