I think either makecode can not preview this code because it is too powerful or there is a bug

I was creating a survival game based on the Rain world videogame. I was trying too create an enemy plant that its purpose was to eat the main character. The plant was made by 5 points that were generated in specific places on the game. Then on game update another point was made to follow each of these plant points with a high speed alternately. If the character touched one of these plant points these plant points would follow the character, grab him and take him to the plants core so the plant could eat him. I made the following point part, but I didn’t finish the part where the plant grabs the character. The game would just get stuck and wouldn’t work. I can create games in other engines but I prefer coding in makecode because it is easier to use.

1 Like

The reason the game is freezing is because of this part of the code:

Could you explain what this code is trying to do? I might be able to point you in the right direction but I’m not sure I have a clear picture of what is supposed to happen.

The freezing is caused by the calls to pause. You should never call pause inside of an on game update event because that code needs to finish running before the screen can be drawn. Instead, use forever if you want to pause.

It also looks like you have a lot of nested loops here, but they are mostly doing the same thing. All of the plant parts have the same kind (which is Player) so each of these loops is trying to loop over the same list of sprites. Be careful here! If you were to remove the destroy sprite block at the end of the innermost loop then this code would try to run 8^6 times for every game update which would slow your game down quite a bit!

1 Like

plantParts are the plant points. The list is the point that follows the five plant points with high speed. If this happens on game update, there will be created a long line, because on every update a plantPart follower is going to be created, and it will follow each of these plant points alternately based on the number( so first the plantPart_1 is going to be followed, than the plantPart_2 and this happens until plantPoint_follower reaches the plantPart_5, that it will be destroyed). Many images were needed to make this plant without these points, because the whole body of the plant was supposed to follow the character, and I wanted that the plant would be good animated, so I found this as the easiest way.

I tried. First of all, change onGameUpdate to Forever with pause() clears all the game update halts. (pause() will yield in forever())
And then the next onGameUpadte with NNNNN*… loop looks like a ‘on overlaps event’ to me.