How do I spawn a particular Family member

Get help using Construct 2

Post » Mon Oct 19, 2015 6:15 am

So I want to do something simple with Families, but don't seem to understand how. Lets say I have a Sprite family called Fruit_Family, and it's full of sprites like Apple, Banana, Orange, etc. So I write an event similar as follows:

On Click of Fruit_Family: Spawn Fruit_Family at point X,Y

Now, what I intend is for the specific fruit being clicked to be what's spawned at the given point. However, Spawning from a family seems to just spawn a random member of that family instead. Is there any way to write this event so it will spawn another of the particular family member I've clicked?
B
12
S
3
G
2
Posts: 13
Reputation: 1,823

Post » Mon Oct 19, 2015 6:29 am

you could use: on click on sprite"Apple": spawn sprite "Apple" at point x,y (and the same for the other member)
or
add instance text variable to your "Fruit_Family" (eg "type") and set the instance var "type"= "Apple" for apple sprite, "type" ="Orange" for orange sprite etc
on click on Fruit_Family
---Fruit_Family.type="Apple": spawn sprite apple at point x,y
---Fruit_Family.type="Orange": spawn sprite Orange at point x,y
--- etc
or you can play with the rex nickname plugin
Image Image
B
22
S
13
G
135
Posts: 871
Reputation: 70,320

Post » Mon Oct 19, 2015 3:02 pm

The first two solutions seem to be functionally identical, in as much as I'd end up having to hard-code a different event/sub-event for each different fruit to spawn. Since I don't necessarily know how many different fruit I'll end up with, though, I was hoping for a cleaner solution, like making it all into one big event that covers any possible types. The Identifying variable seems like it'd be a step in the right direction, if I could spawn a specific object based on that variable, without having to create a separate conditional for each object.
B
12
S
3
G
2
Posts: 13
Reputation: 1,823

Post » Mon Oct 19, 2015 4:18 pm

If you want an individual object to spawn, then just spawn that object, not the family.

If you need to compare Apple, don't compare the fruit family, compare the apple.

At some point you are going to have to determine what you picked. At that point you are going to have to Compare a variable, or the actual object. There is no way that I know of to return the object that was clicked without a bunch of If than statements.

MadSpy has the solutions for you.
B
29
S
8
G
4
Posts: 767
Reputation: 5,985

Post » Sun Nov 22, 2015 1:52 pm

Not solved at all. The proposition seems to suit any needs.

Do you find any solution yet Rex ?
B
14
S
1
Posts: 33
Reputation: 1,022

Post » Thu Nov 26, 2015 7:26 pm

midward wrote:Not solved at all. The proposition seems to suit any needs.

Do you find any solution yet Rex ?


Doesn't seem possible in the way I described within Construct 2, unfortunately. Families don't seem to allow for it. The complicated workaround I ended up with was to have one Universal_Prop_Object that serves as all the various things fruits, and changes properties relative to a spreadsheet based on an Item_Name variable assigned at spawn. More complicated than I was hoping, but easily extensible for various item/fruit types, which was the main thing I was looking for.
B
12
S
3
G
2
Posts: 13
Reputation: 1,823


Return to How do I....?

Who is online

Users browsing this forum: ajcoppersmith, blue visionary, Yahoo [Bot] and 4 guests