Create a family object at runtime....

Get help using Construct 2

Post » Wed Dec 31, 2014 11:46 pm

I'm attempting to create a family object, and specify it's instance variables, however... the family 'member' it creates is at random. How do I specify which object within the family gets created at the point of spawn?

Sure... I can spawn that specific object, which is part of the family instead of spawning the entire family... but I'm looking at an alternate way. Any suggestions?
B
47
S
15
G
3
Posts: 201
Reputation: 4,625

Post » Thu Jan 01, 2015 4:41 pm

I'm actually having this same issue sort of. Help would be apreciated
B
8
S
1
G
1
Posts: 96
Reputation: 632

Post » Thu Jan 01, 2015 5:30 pm

You can't specify which object in a family to create -- the only option currently is to explicitly create the exact object you want.
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,106

Post » Thu Jan 01, 2015 7:29 pm

Then perhaps a feature request.... such as, Create family object, where you can specify the ID of the actual family member. It's too bad this isn't possible.
B
47
S
15
G
3
Posts: 201
Reputation: 4,625

Post » Thu Jan 01, 2015 7:40 pm

You could use the nickname plugin to specify an object to create by name. I believe that's one way around it.

https://www.scirra.com/forum/plugin-nickname-behavior-nickname_t74522
ImageImage
Mr. Green - Platform/puzzle game out now!
B
25
S
7
G
1
Posts: 222
Reputation: 3,350

Post » Thu Jan 01, 2015 10:22 pm

Nitro187 wrote:Then perhaps a feature request.... such as, Create family object, where you can specify the ID of the actual family member. It's too bad this isn't possible.


With respect I'm not sure this really makes sense.

Like, say you have Sprite and Family1, with Sprite a member of Family1.

You're saying something like
System: Create object Family1("Sprite") on layer 0 at (0, 0)

Right now you just do
System: Create object Sprite on layer 0 at (0, 0)

for the same result. Am I understanding correctly?
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Thu Jan 01, 2015 11:45 pm

codah wrote:Right now you just do
System: Create object Sprite on layer 0 at (0, 0)

for the same result. Am I understanding correctly?


Here's an example for what I mean.... say you have a family of particles, that you want to create a single one of whenever a certain object of another family gets destroyed (each particle is different for each sprite).... using current methods, this is not possible... unless you did something like this:

Lets assume sprite1 - 3 are part of Family1, and particle1-3 are part of Family2:

if (sprite1 gets destroyed) -> spawn particle1
if (sprite2 gets destroyed) -> spawn particle2
if (sprite3 gets destroyed) -> spawn particle3

And so on.... now imagine there were 200 objects!!

Now, if there was a system in place like I was suggesting, we could do this... First you would need to set instance variables to determine which part of family2 that family1 will be 'linked' to by giving it the name of the particle:

Lets say that family1's sprite1's variable is set to "particle1", and sprite2 is set to "particle2" etc etc. This could be done at runtime, or in the editor... then :

if(family1 gets destroyed) -> spawn family2(family1.variable)

This would be the only line required to have ALL of the family1 destroyed objects spawn a family2 object. :) I think it'd be a great feature.... if possible...
B
47
S
15
G
3
Posts: 201
Reputation: 4,625

Post » Fri Jan 02, 2015 12:08 am

ok well it does look like you're wanting to spawn by name, as @FredQ has suggested, but I still think the Family behaviour probably isn't the place to shoehorn that into (IMO). So yeah, Nickname is probably your solution.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Fri Jan 02, 2015 12:19 am

FredQ wrote:You could use the nickname plugin to specify an object to create by name. I believe that's one way around it.

https://www.scirra.com/forum/plugin-nickname-behavior-nickname_t74522


Just tried it, and it works great! Thanks for the suggestion. :)
B
47
S
15
G
3
Posts: 201
Reputation: 4,625


Return to How do I....?

Who is online

Users browsing this forum: marc254 and 9 guests