Discuss Scratch

JWmeteor
Scratcher
15 posts

Help with my Shooter Game!

Hello, scratchers! I have this bug in my shooter game, Triangle Man Game, which is a collab between me and @krazyQ.
But there is a bug in the game. The level system works, though! The player can reach the top of the screen to move to the next level and they can go back to the bottom to go to the previous level. It works!
Except the enemy spawning system for the levels. I'm going to try to explain it to you. So basically the enemies aren't spawning on the correct level, and everything is just wonky.
Try the game out for yourself to see the issue. Thanks for reading, and please help the development with the game!
Here is the game's link: https://scratch.mit.edu/projects/1366371219

-@JWmeteor
-duckergames-
New Scratcher
16 posts

Help with my Shooter Game!

I see why. In the enemies sprite, you did
when I receive [next level v]
and then there was a custom block “spawn enemies”

and on the define spawn enemies, you had if :level = 2 then create clone of myself 3 times.

i think why it doesnt spawn on level 2 is because when you were running the spawn enemies custom block script, the level variable has still not caught up to 2, so the custom block thinks its 1.

(i think this is the case tell me if im wrong)

cool game btw

Last edited by -duckergames- (Aug. 5, 2026 15:47:04)

JWmeteor
Scratcher
15 posts

Help with my Shooter Game!

-duckergames- wrote:

I see why. In the enemies sprite, you did
when I receive [next level v]
and then there was a custom block “spawn enemies”

and on the define spawn enemies, you had if :level = 2 then create clone of myself 3 times.

i think why it doesnt spawn on level 2 is because when you were running the spawn enemies custom block script, the level variable has still not caught up to 2, so the custom block thinks its 1.

(i think this is the case tell me if im wrong)

cool game btw
thanks but I don’t really understand

Last edited by JWmeteor (Aug. 5, 2026 16:34:08)

mrgibbles10
Scratcher
25 posts

Help with my Shooter Game!

JWmeteor wrote:

thanks but I don’t really understand
The problem is indeed with the level change system.

In the player sprite, the :Level variable is changed AFTER NextLevel or PreviousLevel is broadcast.
This is why the enemies are spawning in the wrong places, because they are running off of old data.

if <(y position) > (175)> then
broadcast (NextLevel v)
end

when I receive [NextLevel v]
change [:Level v] by (1)
set y to (-175)

The :Level variable change needs to be performed BEFORE NextLevel is broadcast.
At this point, you don't really need to recieve NextLevel or PreviousLevel in the Player sprite; just move those events into the “if” condition:

if <(y position) > (175)> then
change [:Level v] by (1)
set y to (-175)
broadcast (NextLevel v)
end
if <(y position) < (-175)> then
change [:Level v] by (-1)
set y to (175)
broadcast (PreviousLevel v)
end

In addition, here are some other things that I noticed, though not really problems with the code:
  • It doesn't look like there are any more spawns setup for the enemies in the Enemy sprite (SpawnEnemies only has a condition for level two), so enemies will only spawn when ADVANCING into the second level, not returning. The SpawnEnemies block is only called on the NextLevel event, not PreviousLevel event. I would guess that this is intentional.

  • It might also be a good idea to keep track of cleared levels, as returning to level two by first going back to level one will respawn the enemies.

Edit: I also noticed that you can RETURN to level one while fighting the enemies in level two, and they will stay on-screen. Returning BACK to level two will also double the enemies on the screen. You might want to look into this.

I hope this helped!

Last edited by mrgibbles10 (Aug. 5, 2026 21:35:17)

JWmeteor
Scratcher
15 posts

Help with my Shooter Game!

mrgibbles10 wrote:

JWmeteor wrote:

thanks but I don’t really understand
The problem is indeed with the level change system.

In the player sprite, the :Level variable is changed AFTER NextLevel or PreviousLevel is broadcast.
This is why the enemies are spawning in the wrong places, because they are running off of old data.

if <(y position) > (175)> then
broadcast (NextLevel v)
end

when I receive [NextLevel v]
change [:Level v] by (1)
set y to (-175)

The :Level variable change needs to be performed BEFORE NextLevel is broadcast.
At this point, you don't really need to recieve NextLevel or PreviousLevel in the Player sprite; just move those events into the “if” condition:

if <(y position) > (175)> then
change [:Level v] by (1)
set y to (-175)
broadcast (NextLevel v)
end
if <(y position) < (-175)> then
change [:Level v] by (-1)
set y to (175)
broadcast (PreviousLevel v)
end

In addition, here are some other things that I noticed, though not really problems with the code:
  • It doesn't look like there are any more spawns setup for the enemies in the Enemy sprite (SpawnEnemies only has a condition for level two), so enemies will only spawn when ADVANCING into the second level, not returning. The SpawnEnemies block is only called on the NextLevel event, not PreviousLevel event. I would guess that this is intentional.

  • It might also be a good idea to keep track of cleared levels, as returning to level two by first going back to level one will respawn the enemies.

Edit: I also noticed that you can RETURN to level one while fighting the enemies in level two, and they will stay on-screen. Returning BACK to level two will also double the enemies on the screen. You might want to look into this.

I hope this helped!
The enemies on different screens could be fixed by a list or just hiding the clones instead of deleting them for the list option. I was planning to look in onto it. Thanks for your advice! I will try it later since I don’t have much time right now, but thanks! Appreciate you helping!
JWmeteor
Scratcher
15 posts

Help with my Shooter Game!

-duckergames- wrote:

I see why. In the enemies sprite, you did
when I receive [next level v]
and then there was a custom block “spawn enemies”

and on the define spawn enemies, you had if :level = 2 then create clone of myself 3 times.

i think why it doesnt spawn on level 2 is because when you were running the spawn enemies custom block script, the level variable has still not caught up to 2, so the custom block thinks its 1.

(i think this is the case tell me if im wrong)

cool game btw
Hey I understand it now, thanks man! I will check out your game now!
JWmeteor
Scratcher
15 posts

Help with my Shooter Game!

mrgibbles10 wrote:

JWmeteor wrote:

thanks but I don’t really understand
The problem is indeed with the level change system.

In the player sprite, the :Level variable is changed AFTER NextLevel or PreviousLevel is broadcast.
This is why the enemies are spawning in the wrong places, because they are running off of old data.

if <(y position) > (175)> then
broadcast (NextLevel v)
end

when I receive [NextLevel v]
change [:Level v] by (1)
set y to (-175)

The :Level variable change needs to be performed BEFORE NextLevel is broadcast.
At this point, you don't really need to recieve NextLevel or PreviousLevel in the Player sprite; just move those events into the “if” condition:

if <(y position) > (175)> then
change [:Level v] by (1)
set y to (-175)
broadcast (NextLevel v)
end
if <(y position) < (-175)> then
change [:Level v] by (-1)
set y to (175)
broadcast (PreviousLevel v)
end

In addition, here are some other things that I noticed, though not really problems with the code:
  • It doesn't look like there are any more spawns setup for the enemies in the Enemy sprite (SpawnEnemies only has a condition for level two), so enemies will only spawn when ADVANCING into the second level, not returning. The SpawnEnemies block is only called on the NextLevel event, not PreviousLevel event. I would guess that this is intentional.

  • It might also be a good idea to keep track of cleared levels, as returning to level two by first going back to level one will respawn the enemies.

Edit: I also noticed that you can RETURN to level one while fighting the enemies in level two, and they will stay on-screen. Returning BACK to level two will also double the enemies on the screen. You might want to look into this.

I hope this helped!
Thanks again, and I fixed the enemies spawning, but when you kill an enemy in one level, go back one level, then go forwards one level, that enemy you killed is there again! What is a fix for this? Maybe lists, but it might get too complicated. Or maybe just showing and hiding might work!

Powered by DjangoBB