Discuss Scratch
- Discussion Forums
- » Suggestions
- » Scratch Workaround Guide VII
- _nix
-
Scratcher
1000+ posts
Scratch Workaround Guide VII
Okay, thank you! I've added it to the guide.https://scratch.mit.edu/discuss/post/8730447/ Here's the original postI requested a new operator for “mapping” values from one range to another, and @The_Cool_Scratch_Guy (The guy that posted above me) already had this. Here's his code to add to the workarounds: (snip)Can you link us to the post or project where @The_Cool_Scratch_Guy shared this workaround? Also, how does this look for the workaround's adapted code and text, in the guide? (snip)
- _nix
-
Scratcher
1000+ posts
Scratch Workaround Guide VII
After reading the table of contents, I realized that there isn't a Workaround for the sounds category blocks, which is surprising since every other category has been covered. So I figured I would give my suggestion (note, this trick has been widely known & used. However I suggested it to make the list feel more complete and for people who do not know it)I've added the “pause sound, unpause sound” worakround too! Thank you very much!
- Cheezzychiknzzz
-
Scratcher
500+ posts
Scratch Workaround Guide VII
You're welcome, be sure to add in more sound workarounds next timeAfter reading the table of contents, I realized that there isn't a Workaround for the sounds category blocks, which is surprising since every other category has been covered. So I figured I would give my suggestion (note, this trick has been widely known & used. However I suggested it to make the list feel more complete and for people who do not know it)I've added the “pause sound, unpause sound” worakround too! Thank you very much!
- jmdzti_0-0
-
Scratcher
1000+ posts
Scratch Workaround Guide VII
my sound workaround has been sitting in the dust for almost half a year now TOTAfter reading the table of contents, I realized that there isn't a Workaround for the sounds category blocks, which is surprising since every other category has been covered. So I figured I would give my suggestion (note, this trick has been widely known & used. However I suggested it to make the list feel more complete and for people who do not know it)I've added the “pause sound, unpause sound” worakround too! Thank you very much!
Last edited by jmdzti_0-0 (Oct. 1, 2025 17:32:23)
- Cheezzychiknzzz
-
Scratcher
500+ posts
Scratch Workaround Guide VII
Oooooo where is your suggestion? Maybe I can tell it to @_nix!my sound workaround has been sitting in the dust for almost a year now TOTAfter reading the table of contents, I realized that there isn't a Workaround for the sounds category blocks, which is surprising since every other category has been covered. So I figured I would give my suggestion (note, this trick has been widely known & used. However I suggested it to make the list feel more complete and for people who do not know it)I've added the “pause sound, unpause sound” worakround too! Thank you very much!
- jmdzti_0-0
-
Scratcher
1000+ posts
Scratch Workaround Guide VII
found it
A partial workaround for fast-forwarding sounds:define fast-forward (time) seconds of sound
set [pitch v] effect to (500)
wait ((time)/(6)) seconds
set [pitch v] effect to (0)
It's not a perfect skip, but it goes pretty fast. It works fast enough that it can be used for cloud music syncing long as the track isn't too long.
If you don't want the high pitched sound, you could set the volume effect to -100 at the beginning then back to 0 at the end.
Better alternative (better precision)define skip forward (n) secs
if <(n::custom)=(0)> then
stop [this script v]
else
set volume to (0)%
set [pitch v] effect to (360)
set [audio end timestamp v] to ((days since 2000) + (((n)/(86400))/([10^ v] of ((9)/(10))::operators)))
wait until <(days since 2000) > (audio end timestamp)>
set volume to (100)%
end
- _nix
-
Scratcher
1000+ posts
Scratch Workaround Guide VII
found itThanks both. We totally missed this one, yeah…A partial workaround for fast-forwarding sounds:define fast-forward (time) seconds of sound
set [pitch v] effect to (500)
wait ((time)/(6)) seconds
set [pitch v] effect to (0)
It's not a perfect skip, but it goes pretty fast. It works fast enough that it can be used for cloud music syncing long as the track isn't too long.
If you don't want the high pitched sound, you could set the volume effect to -100 at the beginning then back to 0 at the end.
Better alternative (better precision)... // snip
set [pitch v] effect to (360)
set [audio end timestamp v] to ((days since 2000) + (((n)/(86400))/([10^ v] of ((9)/(10))::operators)))
wait until <(days since 2000) > (audio end timestamp)>
... // snip
Can you explain how the second workaround has better precision? I mean, there's two big differences going on here. One is using “days since 2000” instead of plain “wait…seconds”. The other is, I assume, different math. I'm going to try to express the second workaround in terms of “wait…seconds” to make the math easier to compare.
set [audio end timestamp v] to ((days since 2000) + (((n)/(86400))/([10^ v] of ((9)/(10))::operators)))
wait until <(days since 2000) > (audio end timestamp)> // =
wait (((1) / (86400)) * (((n)/(86400))/([10^ v] of (0.9)::operators))) seconds // =
wait ((((1)/(86400)) * ((n)/(86400))) * ((1)/([10^ v] of (0.9)::operators))) seconds // =
wait ((n) / (((86400) * (86400)) * ([10^ v] of (0.9) :: operators))) seconds // =
wait ((n) / (939782784)) seconds
I mean I have to be doing something wrong here.
From a “keep it simple” perspective, assuming the unit conversion is somehow getting flipped over here, 10^0.9 is approximately equal to 7.94, which is pretty close to 6. Is the intended “equal” workaround supposed to be this?
wait ((time) / (6)) seconds // time/6, less accurate
wait ((time) / ([10^ v] of (0.9) :: operators)) seconds // time/7.94, more accurate
Or is this an accidental distraction, time/6 really is accurate, and the only thing that matters is using “days since 2000” instead of “wait…seconds”?
Sorry, I'm just having trouble pulling the better-precision workaround apart, and would appreciate some guidance.
- The_Cool_Scratch_Guy
-
Scratcher
100+ posts
Scratch Workaround Guide VII
A partial workaround for fast-forwarding sounds:~snip~define fast-forward (time) seconds of sound
set [pitch v] effect to (500)
wait ((time)/(6)) seconds
set [pitch v] effect to (0)
Actually it turns out this one is inaccurate (and the other one has way too much math). I did some reading on the scratch wiki a while back and had derived this:
define fast-forward (time) seconds of sound
set [pitch v] effect to [360]
set [old volume v] to (volume)
set volume to [0]
wait (((time) / (8)) - ((1) / (30))) seconds
set [pitch v] effect to [0]
set volume to (old volume)
Ok, let me explain this. First we increase the pitch to the max, which is 360. (I was convinced 500 was the max, but it seems my ears were fooling me.) Then, we turn off the volume so we don't hear anything, then we wait. (We store the volume in a variable to come back to the same volume later.) The math here first divides our time by 8. On the wiki, I found that any increase by 10 is a semitone and 120 is an octave. The latter of these is important, because an octave doubles the speed of the sound. Increasing by 3 octaves, which is our max, makes the speed 2^3, or 8, times faster. After this, we simply account for the screen refresh to maintain accuracy. 1/30 isn't exactly a screen refresh, but it's a good enough approximation.
Speaking of waits, I've been investigating the rest () beats block and think I have the answer to a perfect wait time. Workaround coming soon!
Last edited by The_Cool_Scratch_Guy (Oct. 1, 2025 20:42:01)
- The_Cool_Scratch_Guy
-
Scratcher
100+ posts
Scratch Workaround Guide VII
Just something I noticed, 7.94 is annoyingly close to 8. And it's not even the same number base (2^3 vs. 10^0.9)…………..
- The_Cool_Scratch_Guy
-
Scratcher
100+ posts
Scratch Workaround Guide VII
Okay, thank you! I've added it to the guide.
Can you add the extended version with more variables as well? I think it might be easier to understand for someone who hasn't heard of a scale factor before. Also I am confused why you decide to name the second variable “rounded”, as there is no rounding. Maybe “converted”, “scaled”, or “mapped” would be a better name.
- jmdzti_0-0
-
Scratcher
1000+ posts
Scratch Workaround Guide VII
idk pal i just did some testing and it turned out to work better. the code is not even mine, i found it somewhere and can’t remember the original maker now.
edit: i think i snatched it from @qucchia (?)
Last edited by jmdzti_0-0 (Oct. 7, 2025 00:24:02)
- TopSecretCodes
-
Scratcher
12 posts
Scratch Workaround Guide VII
Is there a workaround for a block like this:
(key pressed)Other than the very long way?
- Cheezzychiknzzz
-
Scratcher
500+ posts
Scratch Workaround Guide VII
Is there a workaround for a block like this:What does this block do?(key pressed)Other than the very long way?
- Imtwentytenth
-
Scratcher
500+ posts
Scratch Workaround Guide VII
There are 2 options:Is there a workaround for a block like this:What does this block do?(key pressed)Other than the very long way?
Reports the last key pressed
Reports the key is pressing
- _nix
-
Scratcher
1000+ posts
Scratch Workaround Guide VII
Ok, let me explain this. First we increase the pitch to the max, which is 360. (I was convinced 500 was the max, but it seems my ears were fooling me.) Then, we turn off the volume so we don't hear anything, then we wait. (We store the volume in a variable to come back to the same volume later.) The math here first divides our time by 8. On the wiki, I found that any increase by 10 is a semitone and 120 is an octave. The latter of these is important, because an octave doubles the speed of the sound. Increasing by 3 octaves, which is our max, makes the speed 2^3, or 8, times faster. After this, we simply account for the screen refresh to maintain accuracy. 1/30 isn't exactly a screen refresh, but it's a good enough approximation.thank you. makes sense! out of interest have you tried this with some simple test audio? like… a sound that has a different percussion effect 1 2 3 4, one percussion per second. 60 bpm, one sound exactly on the beat. and maybe announces the measure number or something. ^^ your theory very much adds up, not doubting it at all, just it's fun to watch things in practice
i had one thought reading your workaround. it's understandable to restore volume to the previous value because you can, but i think it may be better to just mention it as a caveat, next to code that simply “resets” it to 100%. why? because we can't restore the previous value of the pitch effect… unless someone is using a workaround for sounds analogous to the looks-category “color effect reporter” workaround. we could maybe do a “method 2” which shows how to do that. but i think restoring just the volume and not the pitch effect might surprise and confuse people… at least it surprised and startled me
no. sorry, the workaround text is final. (“rounded” is absolutely a typo though, thank you for catching that… just fixed) it's a specific math workaround for a fairly specific math operation. i guess we just disagree that the startrange/endrange explanation is clearer. the guide already brings attention to that in the description of the workaround: “…only the number lines can be different length…”… i feel that's sufficient and that someone working out the math for themselves will be able to figure it out, since they have been told why the math is like this / what the math needs to accomplishOkay, thank you! I've added it to the guide.
Can you add the extended version with more variables as well? I think it might be easier to understand for someone who hasn't heard of a scale factor before. Also I am confused why you decide to name the second variable “rounded”, as there is no rounding. Maybe “converted”, “scaled”, or “mapped” would be a better name.
thank you for telling what you know about the workaround you sharedidk pal i just did some testing and it turned out to work better. the code is not even mine, i found it somewhere and can’t remember the original maker now.
- jmdzti_0-0
-
Scratcher
1000+ posts
Scratch Workaround Guide VII
is that… meant to be sarcastic?thank you for telling what you know about the workaround you sharedidk pal i just did some testing and it turned out to work better. the code is not even mine, i found it somewhere and can’t remember the original maker now.
- _nix
-
Scratcher
1000+ posts
Scratch Workaround Guide VII
not really although sarcasm was an aspect of how i felt, since i was a bit irritated to have our writing cut out so unceremoniously… i did appreciate you commenting what you could and wanted to be direct about thatis that… meant to be sarcastic?thank you for telling what you know about the workaround you sharedidk pal i just did some testing and it turned out to work better. the code is not even mine, i found it somewhere and can’t remember the original maker now.
in your post you seemed to be acting in a disdainful way, “idk pal”, sounding like you were upset or affronted. we did assume you were knowledgeable about the workaround since you were sharing it. that was an assumption on our part, but i feel confused why the assumption upset you (or it seemed that way)
since i figured describing these feelings and trying to help you understand, would be imposing a burden you probably weren't too interested in, i just replied directly so that i was not ignoring you
- gIuey_
-
Scratcher
78 posts
Scratch Workaround Guide VII
for rotating around x: y:
did you mess up here? is the second set x supposed to say set y?define rotate (degrees) degrees around x: (x) y: (y)
set [direction before custom block ran v] to (direction)
get distance to x: (x) y: (y) :: custom // Check out the workaround for this!
point towards x: (x) y: (y) :: custom // Check out the workaround for this, too!
set x to ((x) + ((distance to position) * ([sin v] of (((direction) + (180)) + (degrees)))))
set x to ((x) + ((distance to position) * ([cos v] of (((direction) + (180)) + (degrees)))))
point in direction (direction before custom block ran)
turn cw (degrees) degrees // This helps the sprite look like it's following the circle.
- CodeComet6161
-
Scratcher
1000+ posts
Scratch Workaround Guide VII
Another workaround for
distance to x:[] y:[]::sensing reporter
This requires a blank sprite at a location. It does work, though may be ineffective, especially to those who need a lot of these sprites. There is a solution to this however, you move the original sprite to the desired location.(distance to [sprite v])
- _nix
-
Scratcher
1000+ posts
Scratch Workaround Guide VII
for rotating around x: y:Eep, yes! Totally an error. It's fixed now, thanks.did you mess up here? is the second set x supposed to say set y?define rotate (degrees) degrees around x: (x) y: (y)
... snip :: grey
set x to ((x) + ((distance to position) * ([sin v] of (((direction) + (180)) + (degrees)))))
set x to ((x) + ((distance to position) * ([cos v] of (((direction) + (180)) + (degrees)))))