create particular object in a Family

Get help using Construct 2

Post » Sat Aug 31, 2013 11:52 pm

The manual says:

"If a Family is created, a random object type in the family is picked."

Is there any way or work-around to create a particular member of a family instead of randomly? If I have a family named Enemy with 4 objects: rat, cat, man, woman and I want to control which one of these spawns, how do I do it? I can do this through events but with a lot of planned enemies, the event list could grow quite long.

Alternatively, is there any way to control which sprite to create? Say I want to create a sprite with a particular instance variable out of the many sprite objects I may have?

Thanks!
B
13
S
3
Posts: 17
Reputation: 984

Post » Sat Sep 07, 2013 4:08 am

8 day bump! :D

My workaround/hack is just letting C2 keep on creating random objects from the Family, checking if it's the right one (through it's instance variable) and destroying it if not.

However, it seems very inefficient. For example, even with just 4 objects in the Family (1,2,3,4) it can create 1,1,1,1,2,3,2,3,1 when you're trying to get it to create 4. This means potentially a lot of useless actions before I get the one I actually aim for. Problem just gets worse with more objects in the family.
B
13
S
3
Posts: 17
Reputation: 984

Post » Sat Sep 07, 2013 11:31 am

Not sure if this is suitable for you. Try nickname plugin/behaviour from rexrainbow

http://www.scirra.com/forum/plugin-nickname-behavior-nickname_topic57943.html

You can set the enemy object nickname to "Enemy1"(rat), "Enemy2"(cat), "Enemy3"(man), "Enemy4"(woman). So when you want to spawn cat. You just have to pass in "2" as a function param(Assuming you are using a function to spawn) and in the function nickname:create "Enemy" & function.param(0).

Something like that. However not sure if thats what you want.c4sp3r892013-09-07 11:36:53
B
17
S
8
G
4
Posts: 93
Reputation: 3,190

Post » Sun Sep 08, 2013 12:51 am

Thanks for the reply! I will take a look at that plugin :)

EDIT: This looks like it has excellent potential! Now if I can just get around to actually understanding it lol. Thanks again for pointing me in the right direction. That Rex is amazing!Norbingel2013-09-08 01:30:40
B
13
S
3
Posts: 17
Reputation: 984

Post » Sun Sep 08, 2013 9:29 am

Maybe I'm oversimplifying things here, but why not just create rat, cat, man or woman directly?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sun Sep 08, 2013 3:04 pm

Hi LittleStain,

Thanks for weighing in! That's certainly the easiest and simplest way but, as I said in the OP, with lots of planned enemies or objects, the list can get quite long. This way, I can store all possible objects to spawn in an array and call them from there.

@c4sp3r89 (little harder to type your name :)
I've fiddle with the Nickname plugin a bit and while I can't find a way to simplify it the way I think should be possible yet, it's certainly doing the job better than the way I have it right now. Thanks again!
B
13
S
3
Posts: 17
Reputation: 984


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, Baidu [Spider], Casimir, plinkie, pwrtoppl, resdesign, sublimate and 8 guests