How do I check which object a family just created?

0 favourites
  • 9 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • Let's say I have 100 sprites in family "Sprites", I named them Sprite1, Sprite2, Sprite3, and so on.

    On start of layout: create object "Sprites" on layer 0 at (100, 100)

    Result: A random sprite has been created.

    My question is: how can I check which sprite has been created?

    Because later on I want to match: if, for example, sprite21 has been created, then do something.

  • If you're into 3rd party plugins you could just create the sprite you want in the first place (randomly) rather than leaving it up to the Family to choose. (nickname plugin). Otherwise all my thinking revolves around instance variables (like some ID value) that you'd have to set on all 100 sprites..

  • Thanks for the reply and sorry, but I cannot find a way to either:

    • retrieve the instance variable (as some kind of alias/identifier) of the member of the family, or
    • use UID or IID (as some kind of alias/identifier), because this is not a fixed number

    Perhaps I should not use families the way I want it to use?

    My goal is to check if 2 sprites on screen is true, without writing seperate and similar events for all sprites (if sprite 1 is on screen AND sprite2 is on screen: do something).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • So, "if any 2 (and only 2) sprites (chosen from 100 different sprite object types) are on screen-><do something>"?

  • Almost correct, they are in 2 different groups. Kind of like a head and tail. Or front and back.

    So not "any" 2 sprites, but

    • 2 sprites are randomly created, check if the "head" (following my example) belongs to the "tail".

    So the rest of expression is correct.

  • well I did this before seeing your last post. See if it sparks anything.

    [attachment=1:3atg4g6g][/attachment:3atg4g6g]

    edit: 2 groups. you still need to refine it [attachment=0:3atg4g6g][/attachment:3atg4g6g]

    edit: after re-reading your original post, I think you'll still need a famly instance variable that will match head with tail (e.g. 'head type', 'tail type' or something).

  • Thanks a lot! I just checked it out. It is not what I exactly meant, but at least now I have seen an example of spritefont.

    In your 2nd example:

    Let's say head1 and tail1 are a couple.

    How would you check whether the head and the tail-sprite on screen match?

    So: head1 and tail2 on screen: no match.

    head1, tail1 on screen: match ("do something").

    I am going to try something again with instance variables again. If I have something, I will post it.

  • Thanks a lot! I just checked it out. It is not what I exactly meant, but at least now I have seen an example of spritefont.

    In your 2nd example:

    Let's say head1 and tail1 are a couple.

    How would you check whether the head and the tail-sprite on screen match?

    So: head1 and tail2 on screen: no match.

    head1, tail1 on screen: match ("do something").

    I am going to try something again with instance variables again. If I have something, I will post it.

    If you could state all your requirements at once, I can help, otherwise it's just guessing

  • Codah, thanks.

    I did not write my full requirement, because I thought: instead of telling me how to solve the whole problem (at which point I may seem lazy to find it out on myself), I only asked about one specific thing I thought I would need to solve it.

    My full requirement is:

    There are 30 heads. 30 tails.

    Create one random head. Create one random tail.

    Now check if they belong to eachother.

    I found the solution and it I had to use family instances, just as you said.

    I created only 1 big family (instead of a heads and tails family)

    The big family received 2 instances from me: "head" and "name".

    I did:

    on start of layout:

    global var: CreateAHead=1

    • >create instance from big family
    • > if head = 0: destroy
    • > if head = 1: remember the "name" in another glob var and turn on yet another glob var: "CreateATail" (and set glob var "CreateAHead" to 0)

    With the create a tail-part I did the same as above.

    Final step: if name of head = name of body: it is a match.

    If you think this is very cumbersome, let me know, because I always want to improve my events.

    (just edited this, corrected my English and added a line in the "-> if head = 1: remember the "name"...-sentence.

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