How do I check which object a family just created?

Just started using Construct 2? Post your questions here

Post » Mon Dec 01, 2014 12:03 am

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.
B
28
S
6
G
7
Posts: 681
Reputation: 5,682

Post » Mon Dec 01, 2014 1:51 am

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..
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Mon Dec 01, 2014 6:57 am

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).
B
28
S
6
G
7
Posts: 681
Reputation: 5,682

Post » Mon Dec 01, 2014 7:09 am

So, "if any 2 (and only 2) sprites (chosen from 100 different sprite object types) are on screen-><do something>"?
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Mon Dec 01, 2014 7:16 am

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.
B
28
S
6
G
7
Posts: 681
Reputation: 5,682

Post » Mon Dec 01, 2014 7:21 am

well I did this before seeing your last post. See if it sparks anything.
2_sprites_onscreen.capx


edit: 2 groups. you still need to refine it
2_sprites_different_groups.capx


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).
You do not have the required permissions to view the files attached to this post.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Mon Dec 01, 2014 5:57 pm

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.
B
28
S
6
G
7
Posts: 681
Reputation: 5,682

Post » Mon Dec 01, 2014 9:46 pm

applehiku wrote: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 :)
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Mon Dec 01, 2014 10:31 pm

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.
B
28
S
6
G
7
Posts: 681
Reputation: 5,682


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 3 guests