Discuss Scratch

chickenandcheesesand
Scratcher
100+ posts

Official Scratch Workaround Guide VIII

ScodexPerson wrote:

I have workaround(s) for this block:
<key (... v) pressed for [] seconds? :: sensing>

7.5 key pressed for () seconds?
Method 1: halt the script and check
This method is the simplest consisting of a wait () block to check if the key is still pressed. However, this script will take more time when it's laggy and it can stop other scripts if put in a loop with more than just that.

if <key (... v) pressed?> then
... // add things here if you want something to do immediatly (broadcasting or custom blocks recommended)
wait (seconds :: grey) secs
if <key (... v) pressed?> then
...
end
end

Method 2: calculate seconds with days since 2000
This method uses the days since 2000 block to calculate the time. The adventage is that it can calculate even milliseconds in real-time while other blocks like the timer slow down when there is lag. They calculate time by setting an time of days since 2000 X 86400. That number of 86400 is important because that's the amount of seconds in a day.

For more info on days since 2000, check the article about the days since 2000 block.
The days since 2000 block is useful! :)
if <key (... v) pressed?> then
if <((days since 2000) * (86400)) > ((secssince2000)+(seconds :: grey))> then
...
set [secssince2000 v] to ((days since 2000) * (86400))
end
end
i have already put a method 1 in, but oh well
zispe
Scratcher
500+ posts

Official Scratch Workaround Guide VIII

MythosLore wrote:

Idk if this workaround is good enough but here:

Workaround Type: operators & sensing
Workaround Title: boolean that detects for bad words
if <online? :: sensing> then // to make sure that you have an internet connection so everything doesn't get marked as a bad word
if <(translate (text) to [Thai]) = ()> then // can be any language
set [bad word? v] to [1]
else
set [bad word? v] to [0]
end
else
set [bad word? v] to [undetected]
end
Would this need for those “bad words” to be in the code? If so, obviously, I can't add this as adult language isn't allowed on the Scratch website, even in the project editor.

_nix wrote:

I love the big, bold, colorized numbers, to ctrl+F or scroll to the right workaround. And numbered by category, too, in the sections with more than one category! Reminds me really pleasantly of old text-based GameFAQs guides, which didn't have any clickable links.
I'm glad you like the tweaks I made! I always hate scrolling around to look for something, thought I'd made the ToC a bit more helpful
-
And this is a reminder to follow the template for workarounds to be added! I've read through a couple that didn't use it, remember we're all crunched on time and have daily lives. I promise I'm not just being lazy, the template saves me a lot of time that I need to do personal things (like school work, and the occasional party).
Mark4SISB
Scratcher
58 posts

Official Scratch Workaround Guide VIII

zispe wrote:

MythosLore wrote:

Idk if this workaround is good enough but here:

Workaround Type: operators & sensing
Workaround Title: boolean that detects for bad words
if <online? :: sensing> then // to make sure that you have an internet connection so everything doesn't get marked as a bad word
if <(translate (text) to [Thai]) = ()> then // can be any language
set [bad word? v] to [1]
else
set [bad word? v] to [0]
end
else
set [bad word? v] to [undetected]
end
Would this need for those “bad words” to be in the code? If so, obviously, I can't add this as adult language isn't allowed on the Scratch website, even in the project editor.
This example utilizes the fact that bad words won't be translated into other languages by the translate extension. So no, it does not need a list of bad words. However, the reason why a built-in block for this was rejected in the first place is simple - the only reason you'd care about somebody entering a bad word would be if someone else might see it - aka a cloud chat project, which is banned.
Cheezzychiknzzz
Scratcher
100+ posts

Official Scratch Workaround Guide VIII

I have a workaround for this block:
<mouse pressed for (secs) seconds? :: sensing>
My code for this block is inspired by ScodexPerson's key pressed for () seconds? Block, its so similar in fact, I quoted their post for my post
7.6 mouse pressed for (secs) seconds?
This method is the simplest consisting of a wait () block to check if the key is still pressed. However, this script will take more time when it's laggy and it can stop other scripts if put in a loop with more than just that.

if <mouse down?> then
... // add things here if you want something to do immediatly (broadcasting or custom blocks recommended)
wait (seconds :: grey) secs
if <mouse down?> then
...
end
end
They also have a method 2 where they used the (days since 2000) to calculate the time, but I cannot make a working script for it. Anyone who can make a working script can quote my post and put your script under it!
TiagoTinny
Scratcher
66 posts

Official Scratch Workaround Guide VIII

ZippyZebraZoom85749 wrote:

TiagoTinny wrote:

user id workaround:
put this in the stage
when gf clicked
if <not<[users v] contains (username)?>> then
add (username) to [users v]
end
the reporter
(item # of (username) in [users v])
That won't work, you need cloud variables otherwise it would only record you.
the fixed code:
when gf clicked
set [alphabet v] to [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890]
if <not<[users v] contains (username)?>> then
encode (username)
decode (☁ user)
add (decoded output) to [users v]
end
(item # of (username) in [users v])
define encode (string)
set [encoded output v] to []
set [index v] to [1]
repeat (length of (string))
set [char v] to (letter (index) of (string))
set [char index v] to [1]
repeat (length of (alphabet))
if <(letter (char index) of (alphabet)) = (char)> then
if <(char index) < [10]> then
set [encoded output v] to (join (encoded output) (join [0] (char index)))
else
set [encoded output v] to (join (encoded output) (char index))
end
set [char index v] to (length of (alphabet))
end
change [char index v] by (1)
end
change [index v] by (1)
end
set [☁ user v] to (encoded output)
define decode (numbers)//run without screen refresh
set [decoded output v] to []
set [index v] to [1]
repeat ((length of (numbers)) / (2))
set [code v] to (join (letter (index) of (numbers)) (letter ((index) + (1)) of (numbers)))
set [decoded output v] to (join (decoded output) (letter (code) of (alphabet)))
change [index v] by (2)
end

Last edited by TiagoTinny (May 2, 2026 14:47:03)

ZippyZebraZoom85749
Scratcher
100+ posts

Official Scratch Workaround Guide VIII

Using the “if <> then () else ()” reporter workaround, I found a workaround to clamp reporters.

Workaround Type: Operators
Workaround Title: clamp () in between () and ()
Method 1: if then else statement
Description: Use comparison operators and an if then else block.
if <(number::grey) < (minimum::grey)> then 
set [clamped v] to (minimum::grey)
else
if <(number::grey) > (maximum::grey)> then
set [clamped v] to (maximum::grey)
else
set [clamped v] to (number::grey)
end
end
Method 2: if then else reporter workaround
Description: Use the if then else reporter workaround and put comparison operators in them.
(((minimum::grey) * <(number::grey) < (minimum::grey)>) + ((((maximum::grey) * <(number::grey) > (maximum::grey)>) + ((number::grey) * <not <(number::grey) > (maximum::grey)>>)) * <not <(number::grey) < (minimum::grey)>>))
If an “if then else” reporter existed, it would look a little more like this:
if <(number::grey) < (minimum::grey)> then (minimum::grey) else (if <(number::grey) > (maximum::grey)> then (maximum::grey) else (number::grey)::operators reporter)::operators reporter
You can also backpack the code from this project.

Edit: 100th post

Last edited by ZippyZebraZoom85749 (May 2, 2026 18:11:57)

TimothyLawyer
Scratcher
1000+ posts

Official Scratch Workaround Guide VIII

i noticed method 2 goes off the screen and is a lot of blocks. here's a method with less blocks and almost doesn't go off the screen

Method 3: change number by
Description: use 2 comparison operators and 1 line of code to clamp (sometimes called clip or median of 3 numbers)

change [number v] by ((((min::grey) - (number)) * <(number) < (min::grey)>) + (((max::grey) - (number)) * <(number) > (max::grey)>))

Last edited by TimothyLawyer (May 2, 2026 20:51:30)

Cheezzychiknzzz
Scratcher
100+ posts

Official Scratch Workaround Guide VIII

Bump
zispe
Scratcher
500+ posts

Official Scratch Workaround Guide VIII

Cheezzychiknzzz wrote:

Bump
This topic is stickied, you don't need to bump it.
zispe
Scratcher
500+ posts

Official Scratch Workaround Guide VIII

TimothyLawyer wrote:

i noticed method 2 goes off the screen and is a lot of blocks. here's a method with less blocks and almost doesn't go off the screen

Method 3: change number by
Description: use 2 comparison operators and 1 line of code to clamp (sometimes called clip or median of 3 numbers)

change [number v] by ((((min::grey) - (number)) * <(number) < (min::grey)>) + (((max::grey) - (number)) * <(number) > (max::grey)>))
Is this in reply to post #46 or a different one?
I_wantasheep
Scratcher
1000+ posts

Official Scratch Workaround Guide VIII

Workaround Type: Operators (& Sensing)
Workaround Title: Random Decimal Number
Method: random number times power of ten divided by a power of ten
Description: yow can replace “say” with other blocks
set [decimal places v] to (decimal places :: grey)
say ((pick random ((minimum value :: grey) * (decimal places)) to ((maximum value :: grey) * (decimal places))) / ([10^ v] of (decimal places) :: operators))

Last edited by I_wantasheep (May 6, 2026 14:01:29)

_nix
Scratcher
1000+ posts

Official Scratch Workaround Guide VIII

I_wantasheep wrote:

Workaround Type: Operators (& Sensing)
Workaround Title: Random Decimal Number
Method: divide by a power of ten
Description:
((pick random (minimum value :: grey) to (maximum value :: grey)) / ([e^ v] of (decimal places :: grey) :: operators)
How would someone using this workaround decide the right numbers to type into the minimum value and the maximum value?
I_wantasheep
Scratcher
1000+ posts

Official Scratch Workaround Guide VIII

_nix wrote:

I_wantasheep wrote:

Workaround Type: Operators (& Sensing)
Workaround Title: Random Decimal Number
Method: divide by a power of ten
Description:
((pick random (minimum value :: grey) to (maximum value :: grey)) / ([e^ v] of (decimal places :: grey) :: operators)
How would someone using this workaround decide the right numbers to type into the minimum value and the maximum value?
fair point, let me edit my post
TimothyLawyer
Scratcher
1000+ posts

Official Scratch Workaround Guide VIII

zispe wrote:

Is this in reply to post #46 or a different one?
it's for that post, a clamp method
it may be more clear as a custom block

Method: change number by custom block
Description: use 2 comparisons in 1 line of code to keep a number between a largest and smallest value

define clamp number between (min) and (max)
change [number v] by ((<(number) < (min)> * ((min) - (number))) + (<(number) > (max)> * ((max) - (number))))

feel free to edit to make it better, help it fit
_nix
Scratcher
1000+ posts

Official Scratch Workaround Guide VIII

i think for everyone prioritizing fitting their workarounds on line of code, it's kind of hopeless because the forums just don't fit wide scripts lol. if you're gonna put it in a custom block you might as well use if/else, it's so much easier to read
I_wantasheep
Scratcher
1000+ posts

Official Scratch Workaround Guide VIII

_nix wrote:

i think for everyone prioritizing fitting their workarounds on line of code, it's kind of hopeless because the forums just don't fit wide scripts lol. if you're gonna put it in a custom block you might as well use if/else, it's so much easier to read
imma suggest to be able to scroll scratchblock images wait a sec
TimothyLawyer
Scratcher
1000+ posts

Official Scratch Workaround Guide VIII

finally got one line that fits within the forum margins

((number) + ((<(number) < (min::grey)> * ((min::grey) - (number))) + (<(number) > (max::grey)> * ((max::grey) - (number)))))

as two lines, which may be easier to read

change [number v] by (<(number) < (min::grey)> * ((min::grey) - (number))
change [number v] by (<(number) > (max::grey)> * ((max::grey) - (number)))

as a custom block with if-then control blocks, which is easier to read

define clamp number between (min) and (max) 
if <(number) < (min)> then
set [number v] to (min)
else
if <(number) > (max)> then
set [number v] to (max)
end
end

the latter could also be done sans else

define clamp number between (min) and (max)
if <(number) < (min)> then
set [number v] to (min)
end
if <(number) > (max)> then
set [number v] to (max)
end

which overall is a more compact script

finally doing it without overwriting the input number

define clamp (input) between (min) and (max)
set [output v] to (input)
if <(input) < (min)> then
set [output v] to (min)
end
if <(input) > (max)> then
set [output v] to (max)
end

in that way this is like the first example in this post
zispe
Scratcher
500+ posts

Official Scratch Workaround Guide VIII

Hey guys I promise I'll be adding all this soon, I had a long essay to write that I put off until last minute but I'll work on this tomorrow or next week :p

EDIT, they've been added!

Last edited by zispe (Yesterday 20:18:41)

Powered by DjangoBB