Create family instance where variable = x

Get help using Construct 2

Post » Mon Sep 24, 2012 3:54 pm

I have a family of objects and i create a random one by using

System -> Create object MyFamilyObject

I know this works in a way that it will select a random instance in the family

What I would like to do is filter what it selects from based on an instance variable of the family

The idea is the family object holds all enemies, and i spawn them randomly but i would like it to just spawn the enemies for level1 on level1 using an instance variable called LevelNumber, hope i am making sense
B
11
S
2
G
3
Posts: 95
Reputation: 3,028

Post » Mon Sep 24, 2012 4:07 pm

You have to write a condition for each enemy type and create exactly the object type (family member) of the enemy if the condition is met. But than you can access them through family object.

if varEnemy="Goblin"
   -> create object type "Goblin"
if varEnemy="Troll"
-> create object type "Troll"

It's a pity you can't do it with a variable of the family object. There are also some workarounds with different animations for different enemy types:

http://www.scirra.com/forum/topic57078.html
B
42
S
11
G
4
Posts: 505
Reputation: 7,267

Post » Mon Sep 24, 2012 4:33 pm

Thanks for getting back to me, I'll go with your suggestion above, bit of a pain but the alternative is having all the same enemies in all the same levels which would kinda suck, thanks for replying so quick!
B
11
S
2
G
3
Posts: 95
Reputation: 3,028

Post » Mon Sep 24, 2012 4:47 pm

How do you access them through the family object after you have created them?
B
11
S
2
G
3
Posts: 95
Reputation: 3,028

Post » Mon Sep 24, 2012 4:55 pm

Ah i see you can access it by family object if the sprite was created in a parent event, nevermind this is too complicated
B
11
S
2
G
3
Posts: 95
Reputation: 3,028

Post » Mon Sep 24, 2012 5:04 pm

Calm down @theames, do you have any CAPX to share?

I can write a extensive post here, but you would prefer read direct to the font:

http://www.scirra.com/tutorials/361/understanding-uid-iid-health-cards-and-rocket-smoke-trail
http://www.scirra.com/tutorials/355/making-character-composed-of-multiple-partsTELLES08082012-09-24 17:04:36
ImageImageImageImageImageImage
B
93
S
20
G
13
Posts: 1,215
Reputation: 18,990

Post » Thu Sep 27, 2012 8:39 am

Thanks for the links but they don't really cover what I'm trying to do. I have a family of enemies and I want to select a random object from the family to create. But I don't want to pick from ALL objects in the family. Just where an instance variable is a certain value
B
11
S
2
G
3
Posts: 95
Reputation: 3,028

Post » Thu Sep 27, 2012 1:31 pm

@theames @xoros

this is a solution to create from a family by name
by creating a random object from family but only keeping the one you need

in this case the objects are wood or stone but are from the same family

example
ImageImage
B
61
S
19
G
6
Posts: 809
Reputation: 9,028

Post » Thu Sep 27, 2012 1:50 pm

@vtrix

seems to be a good work around, but I think it will not always work if you would have like 50-100 objects
B
42
S
11
G
4
Posts: 505
Reputation: 7,267

Post » Thu Sep 27, 2012 2:05 pm

@xoros , yeps its a workaround, use it where you can, not sure at what number it would become a problem, you could up the loopnumbers, i been using it for 20 objects and works very good, i would also like a better way but there isn't for now.
ImageImage
B
61
S
19
G
6
Posts: 809
Reputation: 9,028

Next

Return to How do I....?

Who is online

Users browsing this forum: Justin1967, qaisarehman and 34 guests