Discuss Scratch

BearSlothCoding
Scratcher
1000+ posts

The Workarounds to Frequently Suggested Blocks

This is the newest topic for frequently suggested blocks workarounds. You can find the old one here which is closed. The owner of it has quit Scratch and their account is no longer accessible so I have taken this over.
_______________________________________________________________________________________________


_______________________________________________________________________________________________

By the way, this topic is NOT saying that these blocks should never be added because of workarounds. Here's a quote from Za-Chary that explains this more:

Za-Chary wrote:

Well, there's a couple reasons this is a useful list.

The “previous costume” block is not rejected, but it just hasn't been added to the editor. For those looking for something that works the same as a “previous costume” block, they can look at this topic for a workaround so they can effectively code their project.

The “when stop sign clicked” block is rejected, so we will not be adding it (and in this case, yes, there is something “wrong” with implementing the suggestion). Some Scratchers still might like to simulate its effects, however, so they can look at this topic for a workaround so they can accomplish what the block would do.

The purpose of this topic isn't to tell you to “stick” to workarounds — it's to provide you workarounds for blocks that you might be looking to use. It will likely save you time by using the workaround instead of waiting for us to implement a block.

Last edited by BearSlothCoding (Aug. 26, 2020 19:32:13)

BearSlothCoding
Scratcher
1000+ posts

The Workarounds to Frequently Suggested Blocks

Motion blocks :: hat :: motion
_______________________________________________________________________________________________

point towards x:() y:() :: motion
This can be done with two methods.
Method 1:
Create a sprite and move it to where you want it. Say for example, you have a sprite X and move it to x:0 y:0, you could do this:
(for sprite X)
when green flag clicked
go to x:(0) y:(0)
(for the other sprite)
when green flag clicked
forever
point towards [X v]
end
Method 2:
Or you could do this complicated code.
set [deltax v] to ((WantedX) - (x position))
set [deltay v] to ((WantedY) - (y position))
if <not <(deltay) = [0]>> then

if <(deltay) > (0)> then
point in direction ([atan v] of ((deltax)/(deltay))
else
point in direction ([atan v] of (((deltax)/(deltay)) + (180)))
end
else
if ((deltax) > (0)) then
point in direction (90)
else
point in direction (-90)

end
_______________________________________________________________________________________________

bounce :: motion
can be made with this script:
point in direction ((direction) - (180)

Last edited by BearSlothCoding (July 12, 2020 01:04:31)

BearSlothCoding
Scratcher
1000+ posts

The Workarounds to Frequently Suggested Blocks

Looks Blocks :: hat :: looks
_______________________________________________________________________________________________

previous costume :: looks
This can be done with a very simple script:
switch costume to ((costume #) - (1))
You can also use this project which contains a previous costume hacked block.
_______________________________________________________________________________________________

shown? :: looks :: reporter
Can be done with:

set [shown? v] to [yes]//Put this right after the "show" block

set [shown? v] to [no]//Put this right after the "hide" block

Last edited by BearSlothCoding (July 27, 2020 03:00:02)

BearSlothCoding
Scratcher
1000+ posts

The Workarounds to Frequently Suggested Blocks

Sound Blocks :: hat :: sound
_______________________________________________________________________________________________

next sound ::sound
can be done with this:
when gf clicked
forever
play sound (sound#) until done
end

change [sound# v] by (1)

Similarly,
previous sound ::sound
can be done with this:
when gf clicked
forever
play sound (sound#) until done
end

change [sound# v] by (-1)
_______________________________________________________________________________________________

pause sound :: sound
or
resume sound :: sound
can be done with two methods.

You can find the first method in this project by xXRedTheCoderXx.

The second method you can find here by EIephant_Lover.

I did not provide the scripts here because the second one is very long and it wouldn't be fair to include one method but not the other just because one is long.

Last edited by BearSlothCoding (June 10, 2020 17:42:25)

BearSlothCoding
Scratcher
1000+ posts

The Workarounds to Frequently Suggested Blocks

Events Blocks :: hat :: events
_______________________________________________________________________________________________

when ( :: more blocks) clicked :: hat :: events
A when stop signed clicked block is rejected but you can achieve it with this script:
when green flag clicked
forever
reset timer

when [timer v] > (0)
do something

when [timer v] > (0)
forever
reset timer
end

Alternatively, you could also do this method which has less delay but uses a variable:

when green flag clicked
forever
set [timer v] to (timer)

when [timer v] > (timer :: variables)
do something
_______________________________________________________________________________________________

when <something> is done :: hat :: events
can be done with this script:
when green flag clicked
broadcast [Continue v]

when [timer v] > (timer :: variables)
broadcast [Continue v]

when I receive [Continue v]
broadcast [Check v]
forever
set [timer v] to (timer)
when I receive [Check v]
forever
if <something happens> then
do something
end
_______________________________________________________________________________________________

broadcast [ v] received? :: boolean :: events

The traditional method is the following code:

when green flag clicked
set [received? v] to [False]

when I receive [Message v]
set [received? v] to [True]

when green flag clicked
repeat until <(received?) = [True]>
Do stuff
end
do other stuff

But some people don't like the amount of variables in large projects and don't want to add more, which in that case you can use this method where it uses a list instead of three variables:

when green flag clicked
replace item (1 v) of [list v] with [False]
replace item (2 v) of [list v] with [False]
replace item (3 v) of [list v] with [False]

when I receive [Event 1 v]
replace item (1 v) of [list v] with [True]

when I receive [Event 2 v]
replace item (2 v) of [list v] with [True]

when I receive [Event 3 v]
replace item (3 v) of [list v] with [True]

when green flag clicked
repeat until <(item (1 v) of [list v] :: list) = [True]>
Do Stuff
end
repeat until <(item (2 v) of [list v] :: list) = [True]>
Do Stuff
end
repeat until <(item (3 v) of [list v] :: list) = [True]>
Do Stuff
end


_______________________________________________________________________________________________

when costume switches to [ v] :: events :: hat

Can be done with:
wait until <(costume [number v] :: looks) = []>

Last edited by BearSlothCoding (Aug. 18, 2020 15:21:09)

BearSlothCoding
Scratcher
1000+ posts

The Workarounds to Frequently Suggested Blocks

Control Blocks :: hat :: control
_______________________________________________________________________________________________

 while < . . . > { . . . } @loopArrow :: control 
can be done by doing this:
 repeat until < not < . . . > >
...
_______________________________________________________________________________________________

if <...> then {
...
} else if <...> {
...
} :: control

Can be done with:

if <...> then 
...
else
if <...> then
...
end
end

Last edited by BearSlothCoding (July 27, 2020 03:18:17)

BearSlothCoding
Scratcher
1000+ posts

The Workarounds to Frequently Suggested Blocks

Sensing Blocks :: hat :: sensing
_______________________________________________________________________________________________

am i a clone? :: boolean :: sensing
can be made with this script:
when green flag clicked
set [am i a clone? v] to [false]

when i start as a clone
set [am i a clone? v] to [true]

when green flag clicked
forever
if <(am i a clone?) = [true]> then
do something

or you could also do this slightly more effective method:

when green flag clicked
switch costume to [Sprite Costume v]

when I start as a clone
switch costume to [Clone Costume v]

when I receive [Do Stuff v]
if <(costume) = [Sprite Costume]> then
do something
end
if <(costume) = [Clone Costume]> then
do something else
end
_______________________________________________________________________________________________

<key [enter v] pressed?>

can be created with this:
key (join [enter] []) pressed?
This can be used for other single character special keys, such as ; ‘ , \ as well as enter.
But it doesn’t not work with the shift, control, tab, etc. keys.

Last edited by BearSlothCoding (May 28, 2020 18:28:16)

BearSlothCoding
Scratcher
1000+ posts

The Workarounds to Frequently Suggested Blocks

Operator Blocks :: hat :: operators
_______________________________________________________________________________________________

(this) xor (that) :: boolean :: operators
can be made with this:
<not<(this) = (that)>>
_______________________________________________________________________________________________

true :: boolean :: operators 
can be made with this:
<[1]=[1]>
_______________________________________________________________________________________________

false :: boolean :: operators 
can be made with this:
<[1]>[2]>
_______________________________________________________________________________________________

letters (start) through (end :: variables) of (string) :: reporter :: operators
can be done with this:
set [iterator v] to (start)
set [result v] to []
repeat until (((end :: variables)- (start))+(1)
set [result v] to (join (result) (letter (iterator) of (string)))
end
_______________________________________________________________________________________________

() ≥ () :: boolean :: operators
can be done with:
<not <()<()>>
_______________________________________________________________________________________________

() ≤ () :: boolean :: operators
can be done with:
<not <()>()>>
_______________________________________________________________________________________________

[sign v] of () :: reporter operators // reports "1" if the input is positive, "-1" if negative, and "0" when the number is 0.
can be workarounded with:
(((n) / ([abs v] of (n)))+(0))

Last edited by BearSlothCoding (Aug. 6, 2020 23:00:19)

BearSlothCoding
Scratcher
1000+ posts

The Workarounds to Frequently Suggested Blocks

Variable Blocks :: hat :: variables
_______________________________________________________________________________________________

List Blocks :: hat :: list
_______________________________________________________________________________________________

item [last v] of [list v] :: list
item (length of [list v]) of [list v] :: list
_______________________________________________________________________________________________

copy list [ v] to list [ v] :: list
when I receive [ v]
delete (All v) of [list b v]
set [# v] to [0]
repeat (length of [list a v] :: list)
change [# v] by (1)
add (item (#) of [list a v] :: list) to [list b v]
end
_______________________________________________________________________________________________

(item [random v] of [list v] :: list)

(item (pick random (1) to (length of [list v])) of [list v] :: list)

Last edited by BearSlothCoding (Aug. 7, 2020 15:06:48)

PizzaAddict4Life
Scratcher
1000+ posts

The Workarounds to Frequently Suggested Blocks

You forgot the “Lists” block.

Ill report my reply to be deleted once you add it.

Also reporting to be stickied
BearSlothCoding
Scratcher
1000+ posts

The Workarounds to Frequently Suggested Blocks

PizzaAddict4Life wrote:

You forgot the “Lists” block.

Ill report my reply to be deleted once you add it.

Also reporting to be stickied
I figured I would add it in with the variables since that is where they are in the editor. It already is stickied, but thank you.
PizzaAddict4Life
Scratcher
1000+ posts

The Workarounds to Frequently Suggested Blocks

BearSlothCoding wrote:

PizzaAddict4Life wrote:

You forgot the “Lists” block.

Ill report my reply to be deleted once you add it.

Also reporting to be stickied
I figured I would add it in with the variables since that is where they are in the editor. It already is stickied, but thank you.

Ah got it! That makes sense.

Do you still want me to delete my post?
BearSlothCoding
Scratcher
1000+ posts

The Workarounds to Frequently Suggested Blocks

PizzaAddict4Life wrote:

BearSlothCoding wrote:

PizzaAddict4Life wrote:

You forgot the “Lists” block.

Ill report my reply to be deleted once you add it.

Also reporting to be stickied
I figured I would add it in with the variables since that is where they are in the editor. It already is stickied, but thank you.

Ah got it! That makes sense.

Do you still want me to delete my post?
No, it's fine. I don't any more reserved.
fdreerf
Scratcher
1000+ posts

The Workarounds to Frequently Suggested Blocks

I'm sure creating all those posts with the 60-second rule was funnnnnn
Also by “this or that” you mean "this XOR that", correct?

Last edited by fdreerf (May 28, 2020 02:16:43)

BearSlothCoding
Scratcher
1000+ posts

The Workarounds to Frequently Suggested Blocks

fdreerf wrote:

I'm sure creating all those posts with the 60-second rule was funnnnnn
Sure was! To make sure all of my posts were in a row with nobody else interrupting it, I just did the
 Block section :: hat 
at first which takes like 20 seconds. Then I had to wait a while for every. Single. One.

fdreef wrote:

Also by “this or that” you mean "this XOR that", correct?
Oh yes, sorry. I'll fix that.

Last edited by BearSlothCoding (May 28, 2020 02:22:19)

BearSlothCoding
Scratcher
1000+ posts

The Workarounds to Frequently Suggested Blocks

Oh my god, I'm finally done. If only the old topic wasn't closed, then I could have quoted it and copy+pasted it instead of spending nearly 2 hours of my life doing this. Don't get me wrong, I wanted to recreate this sticky, I just didn't want to spend 2 hours figuring out scratchblocks.

But I definitely now know a lot more about scratchblocks and how to create more blocks.
Za-Chary
Scratcher
1000+ posts

The Workarounds to Frequently Suggested Blocks

BearSlothCoding wrote:

Oh my god, I'm finally done. If only the old topic wasn't closed, then I could have quoted it and copy+pasted it instead of spending nearly 2 hours of my life doing this. Don't get me wrong, I wanted to recreate this sticky, I just didn't want to spend 2 hours figuring out scratchblocks.

But I definitely now know a lot more about scratchblocks and how to create more blocks.
If you asked, I could have re-opened the old topic so you could quote it — but perhaps, due to your bolded statement, it was good practice for you to do this anyway.
BearSlothCoding
Scratcher
1000+ posts

The Workarounds to Frequently Suggested Blocks

Za-Chary wrote:

BearSlothCoding wrote:

Oh my god, I'm finally done. If only the old topic wasn't closed, then I could have quoted it and copy+pasted it instead of spending nearly 2 hours of my life doing this. Don't get me wrong, I wanted to recreate this sticky, I just didn't want to spend 2 hours figuring out scratchblocks.

But I definitely now know a lot more about scratchblocks and how to create more blocks.
If you asked, I could have re-opened the old topic so you could quote it — but perhaps, due to your bolded statement, it was good practice for you to do this anyway.
I was thinking about asking that, but I figured it would sound/be kind of lazy. I also figured that if I didn't know how to make the blocks on my own, then I wouldn't fit for running this. I can't teach something if I don't know it. Plus, I'm sure this new knowledge will prove useful in the future.
Nambaseking01
Scratcher
1000+ posts

The Workarounds to Frequently Suggested Blocks

also, this is your second sticky (or third - idk)
BearSlothCoding
Scratcher
1000+ posts

The Workarounds to Frequently Suggested Blocks

Nambaseking01 wrote:

also, this is your second sticky (or third - idk)
Second, but my first won't last long. It's about the server troubles we've been having and they won't last forever. I think.
“Won't last long” 3 months later… ;-;

Last edited by BearSlothCoding (Aug. 26, 2020 23:01:49)

Powered by DjangoBB