Discuss Scratch

5p1r1t
Scratcher
7 posts

Need help with simplifying code.

Hey guys, I really need help with a sprite in my project.

Here's the link: https://scratch.mit.edu/projects/694318994/editor/

There is a really long script in the ‘asteroids’ sprite and I need to find a way to simplify it. The purpose of the script is to slightly increase the spawning rate of asteroids over time.

The project is fine right now but the reason I posted this on forums is that whenever I update the project, it gets really glitched. I tried to add a play again button when the game ends, but when you click on it, the asteroids will clone up at one area and multiply the cloning rate at once, which I don't really want to happen.
Nezon
Scratcher
1000+ posts

Need help with simplifying code.

Use a list and loop through each timing. Set i to 0, change i by 1, detect if item i of list is > timer, wait item i in list2 (how long to wait)

This is my signature (it goes automatically under every post I make)! Here is a bit of advice on foruming, by the way. Don't do SAND. SAND means four words.
SAND means Spam, Advertising, Necroposting, and Derailing.
Spam is when a irrelevant message is sent to many places. Wiki Article: Spam
Advertising is when you promote your studios and projects. Wiki Article: Advertising
Necroposting is when you post on a old topic. It distracts other helpers! Wiki Article: Necroposting
Derailing is when you post something that is irrelevant to the topic, like minimodding. It is called thread hijacking. Wiki Article: Derailing(Derailing idea comes from this guy),
in the process of leaving scratch.
bob has been hidden again :(

5p1r1t
Scratcher
7 posts

Need help with simplifying code.

Ok, will try, thanks.

But will the ‘create clone of myself’ block remain as it is?
Nezon
Scratcher
1000+ posts

Need help with simplifying code.

5p1r1t wrote:

Ok, will try, thanks.

But will the ‘create clone of myself’ block remain as it is?
Yes

Make sure to detect when to stop! If i > length of list stop this script

Last edited by Nezon (May 25, 2022 06:08:04)


This is my signature (it goes automatically under every post I make)! Here is a bit of advice on foruming, by the way. Don't do SAND. SAND means four words.
SAND means Spam, Advertising, Necroposting, and Derailing.
Spam is when a irrelevant message is sent to many places. Wiki Article: Spam
Advertising is when you promote your studios and projects. Wiki Article: Advertising
Necroposting is when you post on a old topic. It distracts other helpers! Wiki Article: Necroposting
Derailing is when you post something that is irrelevant to the topic, like minimodding. It is called thread hijacking. Wiki Article: Derailing(Derailing idea comes from this guy),
in the process of leaving scratch.
bob has been hidden again :(

5p1r1t
Scratcher
7 posts

Need help with simplifying code.

Thanks, I will close this topic once it works.
Nezon
Scratcher
1000+ posts

Need help with simplifying code.

5p1r1t wrote:

Thanks, I will close this topic once it works.
Alright

This is my signature (it goes automatically under every post I make)! Here is a bit of advice on foruming, by the way. Don't do SAND. SAND means four words.
SAND means Spam, Advertising, Necroposting, and Derailing.
Spam is when a irrelevant message is sent to many places. Wiki Article: Spam
Advertising is when you promote your studios and projects. Wiki Article: Advertising
Necroposting is when you post on a old topic. It distracts other helpers! Wiki Article: Necroposting
Derailing is when you post something that is irrelevant to the topic, like minimodding. It is called thread hijacking. Wiki Article: Derailing(Derailing idea comes from this guy),
in the process of leaving scratch.
bob has been hidden again :(

RT_Borg
Scratcher
1000+ posts

Need help with simplifying code.

Hi 5p1r1t,

I“m glad you asked. I can help ”refactor" this code. I'm looking at it now. It will take a little bit of time to make changes and write about them.

EDIT: Looks like you got the help you needed. Let us know if you still want help making it work.

– RT_Borg

Last edited by RT_Borg (May 25, 2022 07:09:35)

5p1r1t
Scratcher
7 posts

Need help with simplifying code.

RT_Borg wrote:

Hi 5p1r1t,

I“m glad you asked. I can help ”refactor" this code. I'm looking at it now. It will take a little bit of time to make changes and write about them.

– RT_Borg

Okay. Sure.
Jlerpy
Scratcher
500+ posts

Need help with simplifying code.

My first thought is that you could maybe simplify the difficulty progression to a single multiplier which could apply to the wait time?
RT_Borg
Scratcher
1000+ posts

Need help with simplifying code.

RT_Borg wrote:

I'm glad you asked. I can help “refactor” this code. I'm looking at it now. It will take a little bit of time to make changes and write about them.

5p1r1t wrote:

Okay. Sure.
Maybe something like the modification in Asteroids, here:
https://scratch.mit.edu/projects/696146756

I left your original “guide end” script, just detached from the event, for easy comparison.

I created a list for the “ASTEROID-DIFFICULTY-SCHEDULE” if a “when green flag clicked”, because you didn't have a simple jump between your difficulty stages, but if you wanted to change them on regular intervals (eg. every 20 seconds or something) you could eliminate the list.

It should be easy to tune the initial delays at the top of the new “guide end” script for each difficulty. I attached a comment where you can change a value to make stages grow in difficulty either slower or faster (that is, how much the delay between clones changes from one stage to the next).

I hope this helps. Happy to answer any questions,

– RT_Borg

Last edited by RT_Borg (May 25, 2022 07:29:54)

5p1r1t
Scratcher
7 posts

Need help with simplifying code.

RT_Borg wrote:

RT_Borg wrote:

I'm glad you asked. I can help “refactor” this code. I'm looking at it now. It will take a little bit of time to make changes and write about them.

5p1r1t wrote:

Okay. Sure.
Maybe something like the modification in Asteroids, here:
https://scratch.mit.edu/projects/696146756

I left your original “guide end” script, just detached from the event, for easy comparison.

I created a list for the “ASTEROID-DIFFICULTY-SCHEDULE” if a “when green flag clicked”, because you didn't have a simple jump between your difficulty stages, but if you wanted to change them on regular intervals (eg. every 20 seconds or something) you could eliminate the list.

It should be easy to tune the initial delays at the top of the new “guide end” script for each difficulty. I attached a comment where you can change a value to make stages grow in difficulty either slower or faster (that is, how much the delay between clones changes from one stage to the next).

I hope this helps. Happy to answer any questions,

– RT_Borg

Thank you so much! I tried it and the spawning of asteroids seem fixed.

Can I add your code to my project and test any new features on it? I'll give you credit in the description.
RT_Borg
Scratcher
1000+ posts

Need help with simplifying code.

5p1r1t wrote:

Thank you so much! I tried it and the spawning of asteroids seem fixed.

Can I add your code to my project and test any new features on it? I'll give you credit in the description.

I'm glad that worked for you. Even more important is understanding the code, so you'll be able to write things like this in the future, so if you have any questions about how it works, don't hesitate to ask.

Feel free to use my suggested code in your project.

I'll leave my remix up for a couple days, but if you want to test features without maybe breaking your “known working” code, you can make a test copy of your own project from the Editor. In the File menu, pick “Save as a copy”.

If your project is called “My Project” and you save as a copy, the new one will immediately be loaded in the editor (in place of the original) and will be called “My Project copy”. This name is inconvenient, because unless the name is really short, you can't look at the project names and see which is the copy, because it gets cut off. I suggest the first thing you do when you make a copy and it loads into your editor is to change the name by adding the word COPY at the beginning, so it's always easy to tell. You'll make less mistakes changing the wrong version (or even deleting the wrong one).

This is a fun game (I played it a bunch while I was testing changes)!

– RT_Borg
5p1r1t
Scratcher
7 posts

Need help with simplifying code.

Thanks! Also I might be a new scratcher but I actually have a few accounts long back, so I know all this stuff.
I really don't have a lot of experience in cloning so I asked. Thanks for your help guys.

Reporting this topic to be closed.
RT_Borg
Scratcher
1000+ posts

Need help with simplifying code.

I also just realized… you used 1-100 for your asteroid color effect. The color effect range is actually 1-200, if you want the full range (I guess it's 200 for historical reasons having to to with Scratch 2).
5p1r1t
Scratcher
7 posts

Need help with simplifying code.

Lol thanks, that's what I was thinking ‘why are the asteroids only in a few colors?’.

Last edited by 5p1r1t (May 25, 2022 09:32:36)

JoBoTvM
Scratcher
30 posts

Need help with simplifying code.

i am dutch

Powered by DjangoBB