Discuss Scratch

Skeelix
Scratcher
64 posts

Help with automated changing in the y axis with clones.

I have created a system where when the space key is pressed it clones and goes under the clone before it, this happens until it hits the bottom of the screen, where it will then stay there, this is due to screen limits where sprite cant pass the screen, I need to automate a change on the Y axis where when there is 10 blocks, the first block along with all the others will move up to create room for a new block to be placed.
MrKingofScratch
Scratcher
100+ posts

Help with automated changing in the y axis with clones.

Wdym a change on the y axis? (and want is the 10 blocks?)

Last edited by kaj (Tomorrow 00:00:00)
100th post!
BigNate469
Scratcher
500+ posts

Help with automated changing in the y axis with clones.

you could try:
when I start as a clone
...
forever
if <[-180 + 1/2 of sprite costume height (rounded)] > (y position)> then
broadcast [move up v]
end
end

when I receive [move up v]
change y by (sprite costume height)
To find the height of a costume, just go into the costume editor and look at the costume's icon on the left side. Just below it there should be its dimensions

That message will broadcast for all the clones and the original sprite, so you might have to deal with that moving the original sprite by moving it back.

Highlight any part of this signature and press ctrl+shift+down arrow to see the rest of it
forever
if <person asks [what's a signature] :: sensing> then
Redirect to [https://en.scratch-wiki.info/wiki/Signature] :: motion
end
end
Please read the list of Officially Rejected Suggestions before posting a suggestion for Scratch! 100th post
This signature is designed to be as helpful as possible.
View all of the topics you've posted in:
https://scratch.mit.edu/discuss/search/?action=show_user&show_as=topics
View all of your posts:
https://scratch.mit.edu/discuss/search/?action=show_user&show_as=posts
Forum tips:
Don't post in topics where the latest post is over ~2 months old, unless you have something critical to add. Especially in topics that are several years old- it isn't helpful, and is known as necroposting.
Don't post unrelated things in topics, including questions of your own. Make a new topic for your questions.
You can use the
 [color=color name or hexadecimal value here] and [/color] 
tags to color text.
Lesser-known Scratch URLs:
scratch.pizza (redirects to main page)
https://scratch.mit.edu/projects/PROJECT ID HERE/remixtree (replace “PROJECT ID HERE” with project id number. Shows all the remixes of the project, and the remixes of those projects, and the remixes of those projects, and so on, as a chart. Link currently redirects to one of my projects)
View a larger list at: https://scratch.mit.edu/discuss/topic/542480/
Why @Paddle2See's responses are so often identical: https://scratch.mit.edu/discuss/topic/762351/
Skeelix
Scratcher
64 posts

Help with automated changing in the y axis with clones.

BigNate469 wrote:

you could try:
when I start as a clone
...
forever
if <[-180 + 1/2 of sprite costume height (rounded)] > (y position)> then
broadcast [move up v]
end
end

when I receive [move up v]
change y by (sprite costume height)
To find the height of a costume, just go into the costume editor and look at the costume's icon on the left side. Just below it there should be its dimensions

That message will broadcast for all the clones and the original sprite, so you might have to deal with that moving the original sprite by moving it back.


I like this a lot, it seems to be working way better than what I had, but now there is a new issue, the broadcast seems to repeat twice in some parts, and multiplies its change in Y over time the more you click, I'm not sure how to explain this very well so ill link the project below.
Skeelix
Scratcher
64 posts

Help with automated changing in the y axis with clones.

MrKingofScratch
Scratcher
100+ posts

Help with automated changing in the y axis with clones.

Clones also react to broadcasts! So, the following code…
when green flag clicked
set [score v] to [0]
create clone of [myself v]
broadcast [increase score v]

when I receive [increase score v]
change [score v] by (1)

will actually increase the score twice!

To fix this, we can use a variable set to for this sprite only to keep track of what is a clone, and what is the original sprite. In the following code, the is clone? variable is set to for this sprite only.

when green flag clicked
set [score v] to [0]
set [is clone? v] to [1]
create clone of [myself v]
set [is clone? v] to [0]
broadcast [increase score v]

when I receive [increase score v]
if <(is clone?) = [0]> then
change [score v] by (1)
end
I hope this helped!

Last edited by MrKingofScratch (March 29, 2024 13:19:21)


Last edited by kaj (Tomorrow 00:00:00)
100th post!
Skeelix
Scratcher
64 posts

Help with automated changing in the y axis with clones.

MrKingofScratch wrote:

Clones also react to broadcasts! So, the following code…
when green flag clicked
set [score v] to [0]
create clone of [myself v]
broadcast [increase score v]

when I receive [increase score v]
change [score v] by (1)

will actually increase the score twice!

To fix this, we can use a variable set to for this sprite only to keep track of what is a clone, and what is the original sprite. In the following code, the is clone? variable is set to for this sprite only.

when green flag clicked
set [score v] to [0]
set [is clone? v] to [1]
create clone of [myself v]
set [is clone? v] to [0]
broadcast [increase score v]

when I receive [increase score v]
if <(is clone?) = [0]> then
change [score v] by (1)
end
I hope this helped!

Thanks!!, ill try this now!!
BigNate469
Scratcher
500+ posts

Help with automated changing in the y axis with clones.

I found a possible bug (relating to the movement of the clones): for some reason, they keep going up more than 32 spaces (even after you implemented @MrKingofScratch's solution) Seemingly the way to fix this is to remove the
repeat (6)
change y by (((global y) - (y position)) / (3))
end

Warning: this does hide the first clone under the main sprite for some reason.
To fix this, just add
change y by (-32)

Last edited by BigNate469 (March 29, 2024 20:05:24)


Highlight any part of this signature and press ctrl+shift+down arrow to see the rest of it
forever
if <person asks [what's a signature] :: sensing> then
Redirect to [https://en.scratch-wiki.info/wiki/Signature] :: motion
end
end
Please read the list of Officially Rejected Suggestions before posting a suggestion for Scratch! 100th post
This signature is designed to be as helpful as possible.
View all of the topics you've posted in:
https://scratch.mit.edu/discuss/search/?action=show_user&show_as=topics
View all of your posts:
https://scratch.mit.edu/discuss/search/?action=show_user&show_as=posts
Forum tips:
Don't post in topics where the latest post is over ~2 months old, unless you have something critical to add. Especially in topics that are several years old- it isn't helpful, and is known as necroposting.
Don't post unrelated things in topics, including questions of your own. Make a new topic for your questions.
You can use the
 [color=color name or hexadecimal value here] and [/color] 
tags to color text.
Lesser-known Scratch URLs:
scratch.pizza (redirects to main page)
https://scratch.mit.edu/projects/PROJECT ID HERE/remixtree (replace “PROJECT ID HERE” with project id number. Shows all the remixes of the project, and the remixes of those projects, and the remixes of those projects, and so on, as a chart. Link currently redirects to one of my projects)
View a larger list at: https://scratch.mit.edu/discuss/topic/542480/
Why @Paddle2See's responses are so often identical: https://scratch.mit.edu/discuss/topic/762351/

Powered by DjangoBB