# Create random object every X seconds

Get help using Construct 2

### » Tue Sep 20, 2011 11:41 pm

Hey,

I'm making this little game to teach my self C2.

http://dl.dropbox.com/u/26785144/CreateRandom.capx

Explanation:

You move the mouse to move the piece and press Space to change its color.

You have to catch the colored blocks falling from the sky, but to do that you will have to catch it with the right color in the animation.

What I can't find out is how to create a random object every X seconds?

The idea I had was to make a global number variable, f.ex "randomObject"
and make c2 check:
randomObject = 1 = create Blue
randomObject = 2 = create Yellow
randomObject = 3 = create Red
randomObject = 4 = create Green

and every X seconds I would set the value of randomObject to random(1,5).

If I do this, nothing happens.
And I realize if this would work C2 would create multiple objects.
I am pretty much stuck. :/

edit: formattingDabbijo2011-09-20 23:42:36
B
14
S
3
G
2
Posts: 37
Reputation: 1,893

### » Wed Sep 21, 2011 12:05 am

Here's an example. Set a local variable to a random number, then create an object depending on the number.
Scirra Founder
B
415
S
248
G
92
Posts: 25,295
Reputation: 200,994

### » Wed Sep 21, 2011 12:10 am

Thanks so much!
B
14
S
3
G
2
Posts: 37
Reputation: 1,893

### » Wed Sep 21, 2011 12:15 am

catchcolor.capx

Edit: Darn ninja'd by Ash Kyatric
2011-09-21 00:16:06
2017-01-04
New to Construct ? Where to start

Please attach a capx to any help request or bug report !
Moderator
B
312
S
129
G
101
Posts: 7,432
Reputation: 75,388

### » Wed Sep 21, 2011 12:42 am

Thanks Kyatric :)
B
14
S
3
G
2
Posts: 37
Reputation: 1,893

### » Sat Jan 21, 2012 7:45 am

Int! Kyatric you saved my night.
B
212
S
40
G
14
Posts: 136
Reputation: 30,818

### » Mon Nov 05, 2012 12:58 am

Hi Everyone!

I'm new to C2, and I'm trying to make a game for my master thesis.
Basically, it's about a chipmunk that has diabetes type1, and the user has to take care of him. Feed him when he asks, give him the insulin injection, etc.

So, when the chipmunk is hungry, a thinking balloon appears telling you that he's hungry, and all the user needs to do is, click on the food icon and feed him.
When he needs the insulin injection, the process is the same.

What I want is the insulin balloon and the food balloon to appear in random, and then when I click the right button,the thinking balloon dissapears, and then in x seconds it appears again, and so on.

I was handeling this with the 'Every X seconds' event, and then playing arround with the opacity, but what happens is that the hungry balloon appears every 10 seconds and the insulin balloon every 35. But when I click on the food icon, I feed the chipmunk, the ballon dissapears, and 10 seconds later the food balloon appears again, and the insulin button never shows up. It looks like when the action is executed, the timer just restarts....

Any help is welcome...
B
2
Posts: 1
Reputation: 252

Return to How do I....?

### Who is online

Users browsing this forum: faulknermano, kriand and 2 guests