# When you wait for the bird to hatch Then make a clone the game crashes?

Project link: Bird hatching simulator by Devant Studios

What is happening in the project, and what do you want to happen instead?

Screenshots of code:

5 Likes

This rule seems to be causing the problem

When clones > 0, you are increasing this game variable, then creating that many clones. However, when you do that, the condition is still true, so you will repeatedly increase 1, then create that many clones.

Additionally, every clone will also be running that rule.

So if clone was originally set to `1`, then you clone twice (since you increase by one), then you have two clones that each clone three times (increased by one again) = 6 clones, then 6 * 4 = 24 clones, then 24 * 5 = 120 clones, then 120 * 6 = 720 clones in less than 1/10 of a second.[1]

You probably want to make these changes:

1. In the ruleâ€™s conditional, you probably only want the original object to be making the clones, so youâ€™d add â€śand clone index = 0â€ť
2. You would also want to run a check (in the `check once if` block) that the â€ś(self) total clonesâ€ť is less than your target amount of clones (i.e. `(self) total clones < â–¶ď¸Ź Clone`)
3. Donâ€™t increase clone by 1 inside the when clones > 0 rule, because that will make it clone over and over.

1. thatâ€™s n! (n factorial) clones â€“ quite a lot if you know what Iâ€™m saying â†©ď¸Ž

5 Likes

Or just do

``````When clones > 0 {
Set clone to clones
Set clones to 0
Repeat times clone {
Create a clone of this object
}
}
``````

Another way to do it (using AEâ€™s secret block)

``````When clones > 0 {
Set clone to clones
Set clones to 0
Create a clone of this object times (clone)
}
``````

The second one is how Spy Guy 96 and I spawn enemies in our platformers.

Iâ€™ve had clones crash my project too (and I was cloning one at a time too), but that was mainly because it was running player 3.0.0, which is not as stable as player 2.2.3, tho itâ€™s still a good idea to fix the issue so something like this donâ€™t happen againâ€¦

4 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.