How to stop lag in program?

I'm creating a space-invaders-type game for a school project, and my code seems to lag whenever the aliens move. I tried using clones to create 20+ aliens easily, but Snap! seems to lag really badly whenever there are more than three clones on screen. Similarly, when I create multiple alien sprites, the game also lags very badly. Attached is my movement code for the alien sprites:

athariandre_project script pic

Here is set speed:

athariandre_project script pic (1)

Here is alienfunction:

athariandre_project script pic (2)

And here is set health:
athariandre_project script pic (4)

The way the code is formatted is pretty weird, but my functions have to stay the way they are because of project requirements.

how are you creating the aliens?

First turn off visual stepping and start warping

the code you shared looks fine, i think the issue is elsewhere, possibly in the check health block. can you share the project?

it would probably help to figure out what part exactly of the movement causes it to slow down, by removing other blocks/sprites temporarily and testing it. is it still slow if you remove all the health related blocks from alienfunction? what if you get the aliens to not move at all, and just run whatever other code they have (if they have any)?

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