How do I create object family no duplicates

Get help using Construct 2

Post » Sun Jan 01, 2017 1:55 pm

i want to create all the objects in a family at start of layout but without any duplicates.
i have read this can be done with arrays, but im not sure how to do it
please help

Image
B
7
S
1
Posts: 21
Reputation: 522

Post » Sun Jan 01, 2017 2:58 pm

Creating a Family object will give you a random object in that family anyway, so you want to create each object individually.
ImageImageImage
B
71
S
21
G
232
Posts: 3,695
Reputation: 129,866

Post » Sun Jan 01, 2017 4:59 pm

Yes but if I create each individual object I will have to have about 10 events multiplied by 30
I will end up with 300 events just for this small bit of the game
B
7
S
1
Posts: 21
Reputation: 522

Post » Sun Jan 01, 2017 5:08 pm

Then you can look at the Nickname plugin by RexRainbow to help.
viewtopic.php?t=74522&start=0
ImageImageImage
B
71
S
21
G
232
Posts: 3,695
Reputation: 129,866

Post » Sun Jan 01, 2017 5:14 pm

I have tried that plugin but you can't assign any actions to the the nickname of an object
B
7
S
1
Posts: 21
Reputation: 522

Post » Sun Jan 01, 2017 5:16 pm

I have seen this but don't know how to do it

https://www.scirra.com/forum/viewtopic.php?f=147&t=110419
B
7
S
1
Posts: 21
Reputation: 522

Post » Sun Jan 01, 2017 5:39 pm

You give each object a nickname. Then depending on the name (if you use a number there's one less step), you can fill an array with the names and pull names out of the array, using a random number generator.

plugin-smart-random_t163624
ImageImageImage
B
71
S
21
G
232
Posts: 3,695
Reputation: 129,866

Post » Mon Jan 02, 2017 5:51 am

why do you create objects? why not use the hats body and pants objects and have multiple frames, and every 3 seconds or when u need it just change the frame....

and then add a condition of each curent item and check for it if its already existing then reselect another 1... creating objects is a bit cpu intensive... changing frames and using the same object is faster and easier.


youl need a local variable though... to save the curent frame of each item.

now depends on how many hats and pants and items you have on screen... i see you using for each familly ... that means you have quite some objets at 1 time in screen...


edited: here is the capx i was saying proving my knowledge for multiple items, i created instead 1 familly holding the entire sprites, and keeping the 2 variables the curent frame and picked frame.


there are hats/belts/and feet

every 3 seconds for each famillymember we change the pickedframe variable to random 0 , selfanimationframecount

then we check the curentframe variable and picked frame if their not equal then we set curentframe to the pickedframe value and set animation to curentframe

else we pick again a new frame.


however my aproach is only applying to items that are not randomly generated, for that better to use the plugin above i guess... or create the obejcts hats/etc separated from their famillies... and then apply the code in my capx.
B
75
S
22
G
68
Posts: 1,337
Reputation: 43,271

Post » Mon Jan 02, 2017 3:50 pm

Thanks
B
7
S
1
Posts: 21
Reputation: 522


Return to How do I....?

Who is online

Users browsing this forum: David181, jorgmaquoi, unicornspitfire and 21 guests