Clone lag

I'm working on a space exploration and base building game, and i need to reduce lag or the game is unplayable.
How do you make the game not lag when thousands of clones are being used? I don't want to make a 50x50 world due to lag!

LINK: Snap! Build Your Own Blocks

Oh wow. It literally crashed the page when I got the small loading line on the screen (the entire computer screen went black for a second).

Why don't you try using pen - specifically stamp? You'd have to change the way a couple of things work, but it would probably be more feasible.

is way to high a number of clones for there to be any hope of reducing lag. There is a reason why Scratch has a 300 clone limit, and here you are using 7000!

I think it's because your power of your machine (computer) cannot handle lots of clones.

for me it is pretty laggy too, but my computer is pretty powerful. please test projects before posting the answer on a topic.

Not sure what the features of the game are. Trying to get a general idea of what's happening in the game.

Build a clone counter (([length V] of (my [clones V])) that when it exceeds a limit, it starts removing tiles or clones unless it is necessary or in the view of the camera.

You probably don't need thousands of clones lying around, only shuffling with the camera, that most of them are not readily visible.

Actually, It creates all the clones and if it exceeds a certain distance, the clone hides and the scripts start hiding again until they enter the distance again.

...
ah yes, stamp.
Maybe that can work, i'll try that after major events in my roblox studio w.i.p game get made.

Hiding does not have enough lag reduction. It still computes the script for each clone. How about swapping the scripts to hide with scripts to delete the clones?

That would be pretty difficult for, uh... my... "beginner" level, as I would need a way to continuously delete and recreate the clone that it needs.
Also... the planets need to be pretty big or... yeah you'd see a giant barrier very quickly.

like i've said in other posts, the vast vast vast majority of snap slowdown is the amount of blocks that have to run per frame. thousands of clones are no issue as long as they don't individually run scripts.

  • clones will keep the same local variables, position, size, costume, and any other sprite properties from when they were created. you can prevent a large lag spike and many potential mistakes by moving all that setup from the clone start to the loop where the clones get created.
  • sprites already don't render when they're offscreen, it only makes things slower to manually hide them.
  • instead of having every clone move individually, set them to anchor to the parent sprite and then move just that one sprite.
  • instead of having every tile check if the player is touching it to tell the player what kind of tile it's touching, the player can use "my neighbors" in sensing, "(variable) of (sprite)", and "ask" in control to pick out information from only the needed tiles.
  • instead of constantly checking if the "h" variable is below 0 in a loop, check it when you set it on the "when clicked" hat

that should get rid of all the code that runs for each clone and make the project far far faster, almost certainly the most important change you can make. other than that is just reducing the amount of blocks you use, including removing custom blocks.

stamping is also very slow unless you pull a lot of tricks, and even with all the tricks available i'm fairly certain it would still be much slower than clones for your project.

i'm close to finishing up these changes for you to look at and use so feel free to just wait a bit for a project link.

(my other very very detailed posts for reference)