Skip to content

Weird cloning bug in my game

💡 Having trouble with Scratch block assembly? Don’t know how to implement code logic? 🚀 Get Help Now

GD

GameDebugger_Pro

Posted on January 15, 2025 • Intermediate

🐛 Cloning bug in my game - entities not appearing

Hi everyone! I’m working on my game ROTSC II and I’ve encountered a really frustrating bug. In the 2nd level, only some entities and doors are showing up. When I try to add a door or entity, my game says “NO” and doesn’t clone it. Even when I press the clone block multiple times, it just won’t execute!

The weird thing is that this only happens in level 2 - other levels work fine. I’ve checked the project multiple times but can’t figure out what’s causing this issue. Any help would be greatly appreciated! 🙏

SC

ScratchCoder_Expert

Replied 2 hours later • ⭐ Best Answer

Great question @GameDebugger_Pro! Cloning issues like this are usually caused by a few common problems. Let me help you debug this step by step:

🔍 Step 1: Check Clone Limits

Scratch has a limit of 300 clones per sprite. If you’ve reached this limit, new clones won’t be created:

    when flag clicked
set [clone count v] to [0]

when I start as a clone
change [clone count v] by [1]
if <(clone count) > [290]> then
say [Too many clones!] for [2] secs
end

when I start as a clone
if <(clone count) > [290]> then
delete this clone
end
  

🎯 Step 2: Debug Clone Creation

Add debugging messages to see what’s happening:

    when I receive [create entity v]
say [Trying to create clone...] for [1] secs
if <(level) = [2]> then
say [Level 2 detected] for [1] secs
if <(can create clone) = [true]> then
create clone of [Entity v]
say [Clone created successfully!] for [1] secs
else
say [Cannot create clone - conditions not met] for [2] secs
end
end
  

🚪 Step 3: Check Level-Specific Variables

The issue might be with level-specific conditions:

    // Check if level 2 has different spawn conditions
when I receive [start level v]
if <(level) = [2]> then
set [max entities v] to [10]  // Make sure this isn't 0
set [spawn enabled v] to [true]
broadcast [reset clone counter v]
end

// Reset clone counter for each level
when I receive [reset clone counter v]
set [clone count v] to [0]
delete all clones of [Entity v]
  

⚡ Step 4: Fix Common Clone Issues

Here’s a robust clone management system:

    // Main clone creation script
define create entity at (x) (y) type (entity type)
if <(clone count) < [290]> then
set [temp x v] to (x)
set [temp y v] to (y)
set [temp type v] to (entity type)
create clone of [Entity v]
else
say [Clone limit reached!] for [1] secs
end

// In the Entity sprite
when I start as a clone
change [clone count v] by [1]
go to x: (temp x) y: (temp y)
set [entity type v] to (temp type)
switch costume to (entity type)
show

// Clean up when clone is deleted
when I start as a clone
forever
if <(delete me) = [true]> then
change [clone count v] by [-1]
delete this clone
end
end
  

🔧 Step 5: Level 2 Specific Fix

Check if level 2 has any blocking conditions:

    // Make sure level 2 initialization is correct
when I receive [start level 2 v]
set [entities spawned v] to [0]
set [doors spawned v] to [0]
set [spawn blocked v] to [false]
broadcast [clear all entities v]
wait [0.1] secs
broadcast [spawn level 2 entities v]
  

The key is to add debugging messages throughout your code to see exactly where the process is failing. Most likely, there’s a condition in level 2 that’s preventing the clones from being created! 😊

GD

GameDebugger_Pro

Replied 30 minutes later

@ScratchCoder_Expert This is incredibly helpful! Thank you so much! 🎉

I found the issue - it was exactly what you said about level-specific conditions. I had accidentally set a variable that was blocking clone creation in level 2. The debugging messages helped me track it down immediately!

VB

Vibelf_Community

Pinned Message • Moderator

🚀 Need Help with Advanced Game Debugging?

Great problem-solving everyone! For those working on complex games with multiple levels and clone management, our community can help you implement:

  • 🔍 Advanced debugging techniques
  • 🎮 Efficient clone management systems
  • 🏗️ Level loading and state management
  • ⚡ Performance optimization for large games

📚 Related Topics

Ready to master game development and debugging? Get personalized guidance from our expert tutors in the Vibelf app!