# How do I create an object in random positions?

Get help using Construct 2

### » Sat May 23, 2015 12:57 pm

Hi,
In my game I need to create an object randomly in 16 positions. For example, take x positions as 10, 20, 30, 40 and y positions as 10, 20, 30, 40. Now, there are 16 (4*4) possible positions. I want construct 2 to randomly pick x and y positions from the given set of values to create the object. The combination could be (x=10, y=30) or (x=20 or y=40). The combination could be any given value from x and any given value from y, and construct 2 should randomly pick a value from x and y, and create the object at the randomly selected combination of x and y.

Is there anyway to do that?
B
24
S
7
Posts: 337
Reputation: 2,224

### » Sat May 23, 2015 1:07 pm

yes there is definitely way to do this
B
11
S
3
G
1
Posts: 421
Reputation: 1,786

### » Sat May 23, 2015 1:10 pm

@ex32 then tell me how?
B
24
S
7
Posts: 337
Reputation: 2,224

### » Sat May 23, 2015 1:56 pm

Maybe this will help.

the objects SpellFont1 are off screen on start of layout.
The SpellSpot has an Instance Variable (Boolean) named overlapp ( initial state = false)
Your game may not need Functions or some other actions.

and similar but a bit different ,
there is this tutorial for setting random frames of a single sprite.
https://www.scirra.com/tutorials/1436/s ... ndom-order
Last edited by producermark11 on Sat May 23, 2015 3:11 pm, edited 9 times in total.
B
36
S
10
G
4
Posts: 250
Reputation: 7,973

### » Sat May 23, 2015 2:16 pm

Dude, I didn't get you.
B
24
S
7
Posts: 337
Reputation: 2,224

### » Sat May 23, 2015 2:31 pm

Try making it without the Function first, then you may get it.
B
36
S
10
G
4
Posts: 250
Reputation: 7,973

### » Sat May 23, 2015 2:42 pm

Now, I can make the object to appear in random positions but it is moving very fast through all the positions. I want to the object appear for every x second at a random position. The object also have animation frames, which are not playing in this event. @producermark11
B
24
S
7
Posts: 337
Reputation: 2,224

### » Sat May 23, 2015 2:47 pm

Wait,
you said "
In my game I need to create an object randomly in 16 positions.

so I thought you wanted 16 instances of that one object.

But now it sounds like you want one instance of the object to jump from one location to the next randomly every x seconds?

let me come up with something.....
Last edited by producermark11 on Sat May 23, 2015 3:03 pm, edited 1 time in total.
B
36
S
10
G
4
Posts: 250
Reputation: 7,973

### » Sat May 23, 2015 2:59 pm

ok, I think this is what you want.
IMPORTANT,
have only ONE instance of the object off screen,(not 16.)

.
this will make one instance of the object (SpellFont1) set it position at a random Sprite2 for
in this example 1 second.
B
36
S
10
G
4
Posts: 250
Reputation: 7,973

### » Sat May 23, 2015 3:15 pm

Yes, now you understood. Can you help me with this?
B
24
S
7
Posts: 337
Reputation: 2,224

Next