Discuss Scratch

Ronazon7849
Scratcher
45 posts

Mass Duplicating Scripts

Hello, Scratch community,

Is there a way to mass duplicate lines of code? I know that right-clicking duplicates it once, but I want to be able to either duplicate it faster or duplicate it like 20 times at once. Does anyone know? If this doesn't exist, it would be a nice feature to add ctrl-c and ctrl-v to copy and paste.
Purin2022
Scratcher
100+ posts

Mass Duplicating Scripts

Ronazon7849 wrote:

Hello, Scratch community,

Is there a way to mass duplicate lines of code? I know that right-clicking duplicates it once, but I want to be able to either duplicate it faster or duplicate it like 20 times at once. Does anyone know? If this doesn't exist, it would be a nice feature to add ctrl-c and ctrl-v to copy and paste.
Unfortunately, Scratch doesn't really had a way to do that.

The fastest way to do that would be duplicate the whole script and duplicate the whole script again and duplicate the whole script again until it's enough(1 became 2, 2 became 4, 4 became 8 …).

Hopefully you found it helpful!

move () steps

move () steps
move () steps

move () steps
move () steps
move () steps
move () steps

move () steps
move () steps
move () steps
move () steps
move () steps
move () steps
move () steps
move () steps
Ronazon7849
Scratcher
45 posts

Mass Duplicating Scripts

Ok, thank you! This helped a lot.
medians
Scratcher
1000+ posts

Mass Duplicating Scripts

If you want to duplicate it to another object (sprites/the stage), you have to drag the script to that object (as long as it is not selected)
Xcvfdd
Scratcher
500+ posts

Mass Duplicating Scripts

You could use a custom block with the code you want to copy. That way you won’t need to copy the lines of code each time you want to use it.
Example:

Last edited by Xcvfdd (Jan. 26, 2023 02:47:21)

deck26
Scratcher
1000+ posts

Mass Duplicating Scripts

I'm curious why you'd want to do this though. Generally there are better ways than duplicating large bits of code.
Ronazon7849
Scratcher
45 posts

Mass Duplicating Scripts

Xcvfdd wrote:

You could use a custom block with the code you want to copy. That way you won’t need to copy the lines of code each time you want to use it.
Example:

I don’t know if this would work.

Last edited by Ronazon7849 (Jan. 27, 2023 16:15:09)

Ronazon7849
Scratcher
45 posts

Mass Duplicating Scripts

deck26 wrote:

I'm curious why you'd want to do this though. Generally, there are better ways than duplicating large bits of code.

I'm making a username engine.
CODER-J
Scratcher
80 posts

Mass Duplicating Scripts

Loops are generally a better solution, so long as they are inside of a custom block with the “run without screen refresh” box ticked. It will also make the project load faster.

in stead of

move (10) steps
move (10) steps
move (10) steps
move (10) steps
move (10) steps
move (10) steps
move (10) steps
move (10) steps

do

define block set to "run without screen refresh"
repeat (8)
move (10) steps
end

Last edited by CODER-J (Jan. 27, 2023 00:24:18)

Ronazon7849
Scratcher
45 posts

Mass Duplicating Scripts

So let me try to explain it better. I’m making a username script that can save usernames, and the way I know how to do it, I would have to do something like this:

when green flag clicked
set [letter of user] to [0]
repeat (length of (username))
if <<letter (letter of username) of (username)>=[(letter)]> then
Set (user) to (join (user) (join [(space)] [(letter converted to number)]))
change [letter of user] by [1]

end
end

Letter converted to number meaning a = 1, f = 6, z = 26, etc.

The first if would have the letter “a”. If it wasn’t “a” it would continue on to the next script where the letter would be “b”, and so on. This would take quite a long time, and I need a better way to do it.

Last edited by Ronazon7849 (Jan. 27, 2023 16:13:30)

deck26
Scratcher
1000+ posts

Mass Duplicating Scripts

Ronazon7849 wrote:

So let me try to explain it better. I’m making a username script that can save usernames, and the way I know how to do it, I would have to do something like this:

when green flag clicked
set [letter of user] to [0]
repeat (length of (username))
if <<letter (letter of username) of (username)>=[(letter)]> then
Set (user) to (join (user) (join [(space)] [(letter converted to number)]))
change [letter of user] by [1]

end
end

Letter converted to number meaning a = 1, f = 6, z = 26, etc.

The first if would have the letter “a”. If it wasn’t “a” it would continue on to the next script where the letter would be “b”, and so on. This would take quite a long time, and I need a better way to do it.
Set up a list containing the letters (one per item) and use the item # of thing in list. There you have a single block that finds the letter an gives you the corresponding number.

As I said, there should rarely be a need to duplicate code lots of times and this is a prime example. Even without the ‘contains’ block which is a relatively recent addition you could loop through a list of letters to find a match. You should never need to do something like if letter=a, if letter=b, if letter=c ……..
Ronazon7849
Scratcher
45 posts

Mass Duplicating Scripts

That'll work. Thank you! helped a lot.

Powered by DjangoBB