Problems with cloning

I have a problem regarding the cloning of objects

The code is as follows:

Inside the variables, I’ve created a variable

Name of variable:Random seconds
Type:Number
Value=0

Randomize:
min:0.3
max:1
interval
every (0.4)

In event manager:
when:system/runtime/repeat every/Random seconds
Do:Border square/Random number/generate random number

Random number for the border square is:
Min:1
Max:3

When:Border Square/Random number/equal/1
Do:Border Square/clone/clone object/Bomb

Whenever I run this code, it clones big amounts of bombs simultaneously. Also, the random seconds’ min and max values sometimes changes and sometimes not. What’s the issue ?

3 Likes

Your code makes bombs when your variable equals 1.
There’s no code to stop or count the making bombs when variable is 1.
If your Ready program runs at 60 frames a second and the variables value is 1 for 0.3 secs then that would make 20 clones approx.

You could make another variable called BOMBCOUNT.
So code to only create a bomb if the BOMBCOUNT variable is less than 6 (if you want a max of 5 bombs onscreen at a time)
Each time a bombs created add 1 to BOMBCOUNT.
Each time a bombs destroyed minus 1 from BOMBCOUNT

This is just an example that could help you.

4 Likes

Hi @ACCMarkedForDel , try use this values:

Name of variable:Random seconds
Type:Number
Value=1

Randomize:
min:0.3
max:1
interval
every (1.1)

I think in your case errors occur due to the fact that you set the generation of a new number lower than the maximum parameter

3 Likes

@ACCMarkedForDel try this:

Events:

When: System > Runtime > Repeat Every > Random Seconds
Do: Border square > Random Number > Generate Random Number

When: Border Square > Random Number > Equals > 1
AND: System > Runtime > Repeat Every > 0.4
Do: Border Square > Clone > Clone Object > Bomb

2 Likes

Make a event to make It stop after it gets cloned once

2 Likes