• Hi all. We have had reports of member's signatures being edited to include malicious content. You can rest assured this wasn't done by staff and we can find no indication that the forums themselves have been compromised.

    However, remember to keep your passwords secure. If you use similar logins on multiple sites, people and even bots may be able to access your account.

    We always recommend using unique passwords and enable two-factor authentication if possible. Make sure you are secure.
  • Be sure to join the discussion on our discord at: Discord.gg/serebii
  • If you're still waiting for the e-mail, be sure to check your junk/spam e-mail folders

MIT Scratch Sprite Spawning

Cloneydew2000

WildScraggyAppeared!
So, I have started a project on the program "Scratch". It is a top-down Zelda style game, but I need enemies to spawn randomly around the stage. Is this possible? If not I may need to restart, so PLEASE PLEASE if this isn't possible, could you tell me the next best thing? Thanks!
 

Mew The Gato

___________
So, I have started a project on the program "Scratch". It is a top-down Zelda style game, but I need enemies to spawn randomly around the stage. Is this possible? If not I may need to restart, so PLEASE PLEASE if this isn't possible, could you tell me the next best thing? Thanks!

Possible, but it cannot be entirely random. You have to decide the maximum number of enemies that can spawn, and set their positions. For example, they may all start from one position, or have different, defined positions from where they can spawn.

You may use different enemies, or just duplicate a certain enemy for this.

Then, at the note of "Broadcast X", like, say, "Broadcast Spawn Enermy", you can give a number to be set as the variable with the "Pick random X to Y" script and put in numbers.

Like: [Set Variable A to (Pick random X to Y)]

In this way, any of the enemies, which you should "Hide" by using the script when the Green Flag is clicked, have a chance to appear. Say you have 10 set enemies. During the broadcast, there is an extremely low chance for 10 enemies to appear at once. This can also, however, lead to a glitch that shall cause enemies to stop spawning, but that should not be a problem if you can program some sort of backup catalyst. For example, maybe the catalyst is broadcasted every 5 to 10 seconds seconds?

Like:

[Wait (Pick random 5 to 10) seconds]
[Broadcast (Enemy Spawn)]

To avoid the common glitch that comes with the "Forever" script, you can do this, if the monsters only spawn in a certain area. You can use a variable to determine the area.

Like:

[Forever]
[> If [(Stage) = Monster Zone)]
[Wait (Pick random [5] to [10]) seconds]
[Broadcast (Enemy Spawn)]
[>Else]
[Insert nothing here]

And:

[When I receive (Enemy Spawn)]
[Set (variable) to (Pick random [1] to [10]]
[>If (Variable = [1])
[Broadcast (Spawn 1 Enemy)
[>Else]
[>If (Variable = [2]]
[Broadcast (Spawn 2 Enemies)]

And so on...

I hope that helps. If you have any questions, feel free to ask!
 
Last edited:

Mew The Gato

___________
Note that these only include the monster spawning. Their behaviour is another issue.

[IMG139]http://i44.*******.com/28834h1.png[/IMG139]

This one stays invisible and basically just exists for balance.

[IMG139]http://i40.*******.com/2va1lkz.png[/IMG139]

The first of the 10 enemies that can spawn.

[IMG139]http://i41.*******.com/289ew5e.png[/IMG139]

The only difference between Enemy 1 and Enemy 2 is their numbers. Look at their scripts closely -- they have 1 and 2, respectively.

And so on... just change the number. You can change every "10" in there to "100" if you somehow want 100 enemies to spawn, and so on. Remember -- there is a small chance of all of them spawning at once. You must use the "Duplicate" function by right clicking on the sprites in order to create the enemies. You already need 10 sprites for 10 different enemies.

I hope that helped. Also, I made two variables -- "Area" and "Monster Spawn Number". You can change, if that helps.
 

Cloneydew2000

WildScraggyAppeared!
Note that these only include the monster spawning. Their behaviour is another issue.

[IMG139]http://i44.*******.com/28834h1.png[/IMG139]

This one stays invisible and basically just exists for balance.

[IMG139]http://i40.*******.com/2va1lkz.png[/IMG139]

The first of the 10 enemies that can spawn.

[IMG139]http://i41.*******.com/289ew5e.png[/IMG139]

The only difference between Enemy 1 and Enemy 2 is their numbers. Look at their scripts closely -- they have 1 and 2, respectively.

And so on... just change the number. You can change every "10" in there to "100" if you somehow want 100 enemies to spawn, and so on. Remember -- there is a small chance of all of them spawning at once. You must use the "Duplicate" function by right clicking on the sprites in order to create the enemies. You already need 10 sprites for 10 different enemies.

I hope that helped. Also, I made two variables -- "Area" and "Monster Spawn Number". You can change, if that helps.

Mew that's fantastic! Thanks so very much!! (Can I come back when I need to ask about enemy despawns after death?)

EDIT: cant get it to work so far, but I'll get there.
 
Last edited:

Mew The Gato

___________
Mew that's fantastic! Thanks so very much!! (Can I come back when I need to ask about enemy despawns after death?)

EDIT: cant get it to work so far, but I'll get there.

Of course.

Note that you need to have some way to set the area to "Monster Zone", or the chain reaction itself shall not start.

And remember, with this, they only appear, not outright attack. You need to program further for that.

Also, make sure they go back to their original positions after they die. When programming the death of Enemy 1, for example, use the script, [Go to x: (206) y: (-21)], or any other, desired location.

You can post a screenshot yourself, and I may be able to find out the mistake.
 

Cloneydew2000

WildScraggyAppeared!
Of course.

Note that you need to have some way to set the area to "Monster Zone", or the chain reaction itself shall not start.

And remember, with this, they only appear, not outright attack. You need to program further for that.

Also, make sure they go back to their original positions after they die. When programming the death of Enemy 1, for example, use the script, [Go to x: (206) y: (-21)], or any other, desired location.

You can post a screenshot yourself, and I may be able to find out the mistake.

Sure, but I didn't save it. I will do it later and post it here.
 
Top