How to create a random object?

Get help using Construct 2

Post » Sat Aug 18, 2012 11:57 am

I have created four objects called symb0, symb2 .. symb3.

Now I want to spawn one of them.

I can do a System->create object, but this only lets me pick from a list, there is no way to enter an expression such as "symb" + random(4)

any ideas?
B
15
S
5
G
2
Posts: 357
Reputation: 3,691

Post » Sat Aug 18, 2012 11:58 am

I have no idea which forum to post this in (sorry!)nutmix2012-08-18 11:58:42
B
15
S
5
G
2
Posts: 357
Reputation: 3,691

Post » Sat Aug 18, 2012 1:33 pm

Unfortunately there's no way to do that. Spawn/create object by it's name would be a nice addition to C2, but won't happen any time soon due to minify script on export.
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Sat Aug 18, 2012 2:22 pm

Would it work for your project done this way?

Demo

capx
B
79
S
32
G
23
Posts: 119
Reputation: 14,937

Post » Sat Aug 18, 2012 2:25 pm

Moving to 'how do I'.

For now you have to set a variable and create a different object depending on that. If you just want to create a random object, put all the objects in a family and create the family, and a random object belonging to the family will be created.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Sat Aug 18, 2012 2:31 pm

Excellent capx! This works for me.

One quick question - In the editor, you can copy rather than clone object, then you can have one click handler or loop over them etc as they are all instances of the same object.

If you crate instances like in your example, will they be "clones" or "copies"?

I'm guessing they will behave like clones, so I wont be able to have a generic click handler for them all (unless using families?)

Thanks again!
B
15
S
5
G
2
Posts: 357
Reputation: 3,691


Return to How do I....?

Who is online

Users browsing this forum: DemantDigitalArt and 20 guests