How do I create a given object from a family

Get help using Construct 2

Post » Thu Apr 28, 2016 3:22 pm

Hi everyone,

I would like to create a given object from a family based on a variable.
However, the manual says : "[When creating an object] if a Family is chosen, a random object type from the family is picked, and an instance created for that."

To be very clear, I defined a family instance variable "uniqueNumber" and gave every object in the family a different value for it in the properties. Now I would like to create an object from that family based on this variable.

Is there any way to do that?

Thanks a lot! :)
B
29
S
6
G
1
Posts: 347
Reputation: 2,725

Post » Thu Apr 28, 2016 3:46 pm

Do a search for the Nickname plugin. C2 doesn't support this natively.
ImageImageImage
B
71
S
21
G
231
Posts: 3,688
Reputation: 129,352

Post » Thu Apr 28, 2016 3:51 pm

Thanks a lot @blackhornet. Looking into this plugin now.
It looks like once again @rexrainbow will come to help me. :)
B
29
S
6
G
1
Posts: 347
Reputation: 2,725

Post » Fri Apr 29, 2016 7:55 am

I downloaded and tried the Nickname plugin, but I still don't see how it could help me select a given instance of a family based on a number variable.

Sure, I can assign a nickname to each object, but I don't see how it makes it different in my case than just creating each different object.

The problem is that the family's name needs to be a string : "one" instead of 1.
In the latter case I would be able to call the nickname based on the number variable, but I don't see how to do that with the string.

Am I missing something? Or is there any other way to achieve this?
B
29
S
6
G
1
Posts: 347
Reputation: 2,725

Post » Fri Apr 29, 2016 8:11 am

@Rable

Try this sample capx
B
108
S
26
G
267
Posts: 4,456
Reputation: 149,747

Post » Fri Apr 29, 2016 8:57 am

@rexrainbow
Thanks a lot! This is a very interesting plugin and the capx linked helped a lot in understanding it!
It's still a bit mysterious for me at the moment but I can definitely see the potential. I'll see if I can manage to use it properly in my code. :)
B
29
S
6
G
1
Posts: 347
Reputation: 2,725

Post » Fri Apr 29, 2016 9:56 am

To keep you updated, I manage to do what I wanted. And if someone ever needs to do it, I'm going to explain how I did it.

What I had was an array with 40 X entries and a number value in each of them. I wanted to create given object from a family based on this value. For this I created an family instance number variable and assigned a different value for each object in the family.

But as @blackhornet told us that doesn't work, as we can't create a given instance from a family based on a variable. The instance created will always be a random object type from the family.

It was possible however using @rexrainbow 's plugin Nickname. Instead of defining a number instance variable for each object type in the family, I added a family behavior Nickname, and entered a different string (A, B, C, D, ...) for each objet type in it.
I then stock these values in the same array as previously but as strings.

Then the below event just creates an instance from the family (placementTrumpet) which has the same Nickname than stocked into the array at curX.

Image

Exactly what I wanted to achieve, thanks a lot @rexrainbow for the awesome plugin!
B
29
S
6
G
1
Posts: 347
Reputation: 2,725

Post » Fri Apr 29, 2016 12:51 pm

@Rable

Sets "Mode" to "SID" if you don't care the value of nickname ( you will not fill the nickname parameter manually ). Nickname will be filled automatically in this mode. See previous capx (Update rex_bnickname behavior first).
B
108
S
26
G
267
Posts: 4,456
Reputation: 149,747

Post » Fri Apr 29, 2016 1:48 pm

Oh, I wondered what SID was about. I will remember that for the next time. :)
Thanks!
B
29
S
6
G
1
Posts: 347
Reputation: 2,725

Post » Fri Apr 29, 2016 1:57 pm

@Rable

"SID" is the id of object type which created by c2 engine, it is an unique value for each object type.
B
108
S
26
G
267
Posts: 4,456
Reputation: 149,747


Return to How do I....?

Who is online

Users browsing this forum: lukewasthefish, Yahoo [Bot] and 16 guests