# Spawning Random Objects

• 28th October 2012, 08:10 AM
Stu
Spawning Random Objects
Hi,

I just finished the Chocobreak tutorial (in the Games Factory 2, trying that out first) and am working on improving it with improved controls, power ups and so forth. I've figured out how to create new objects so I can spawn power ups when the bricks are broken - the problem is, I don't want them to spawn every time.

So my question is:

• How do you create objects that spawn from a random value?

Currently it's "If Ball Golden has a collision with Milk > Create new Champagne Glass"

But I would prefer that it somehow checked for a random number between say 1 and 4, and if it's a 2, it spawns a champagne glass, if it's a 3, it spawns a muffin, and if it's a 1 or a 4 it spawns nothing. How do you do that in the Games Factory? It's a pretty fundamental question for game dev and I've skimmed some beginner and intermediate tutorials with no luck. All the tutorials I've seen just use timers, but I want it based on random chance, pure chance.

Thanks, this is my first post in this forum, liking the product so far. Looking forward to meeting some of you on here.
Stu
• 28th October 2012, 01:41 PM
LB
You can use the built-in condition for that:
http://i.imgur.com/76VpS.png
• 29th October 2012, 01:22 AM
Stu
Now that you point it out it's blindingly obvious! Thanks!
• 29th October 2012, 02:18 AM
Stu
I'm just trying to get my head around their way of logic, so can you help clarify for me exactly what it means and how to use it?

For example, it comes up with 2 windows. The first says, "Enter the chances" and then "Enter the total number of chances".

So say I said, "Enter the chances = 1" and "Total chances = 4", would that mean there was a 1 in 4 chance of the event occurring? Is that how it works?

Thanks
• 29th October 2012, 02:33 AM
Eliyahu
Yes, that is how it works.
• 29th October 2012, 05:31 AM
Stu
Thanks :) All working good now.