Discuss Scratch

secretuch
Scratcher
100+ posts

Scratch Workaround Guide VII

8to16 wrote:

May I suggest adding the
when (::obsolete) clicked :: events hat
workaround?

when gf clicked
forever
set [timer v] to (timer)
end

when [timer v] > (timer::variables)
...
when @stopSign clicked:: hat events
This is better block
medians
Scratcher
1000+ posts

Scratch Workaround Guide VII

Spaceandmoon1 wrote:

Small question: Why does my ‘pen down’ block not work? I want my pen to be able to draw.
This isn't the place, so can you send the link to the project in the HwS (Help with Scripts) forum?

secretuch wrote:

when @stopSign clicked:: hat events
This is better block
The post was made like a few days before you could actually do that on the forums, so..
Litterbl0cks
Scratcher
100+ posts

Scratch Workaround Guide VII

There's a chance I may have missed it, but here's how to sense stop being pressed!

when green flag clicked
forever
reset timer
end


when [timer v] > (0)
...                      //Put what you want to happen when stop is pressed here!
WsDanzel
Scratcher
52 posts

Scratch Workaround Guide VII

Spaceandmoon1 wrote:

Small question: Why does my ‘pen down’ block not work? I want my pen to be able to draw.
I think u should use pen up instead LOL
medians
Scratcher
1000+ posts

Scratch Workaround Guide VII

WsDanzel wrote:

Spaceandmoon1 wrote:

Small question: Why does my ‘pen down’ block not work? I want my pen to be able to draw.
I think u should use pen up instead LOL
Does the opposite of what was asked:
https://en.scratch-wiki.info/wiki/Pen_Up
That person was asking a serious question LOL

Last edited by medians (Feb. 27, 2025 15:28:49)

The_Cool_Scratch_Guy
Scratcher
100+ posts

Scratch Workaround Guide VII

There's a workaround for timezone detection.

I'm too lazy to write it all in bbcode but I'll give you the gist of it.
It works because the days since 2000 block is in gmt, the timezone in the uk.
You can manually calculate days since 2000, take the difference, multiply by 24 and round to the nearest quarter. This gives you the gmt timezone, e.g. -5 for us east (or -4 in dst).
You would probably figure out why to round if you thought of it carefully, but as for why to the nearest quarter not nearest half, blame Nepal for having a quarter hour offset from India's timezone.
If you want the exact code for manually calculating days since 2000, you can go to my project Custom Date Countdown and find the my block calculate days since 2000.
WsDanzel
Scratcher
52 posts

Scratch Workaround Guide VII

The_Cool_Scratch_Guy wrote:

There's a workaround for timezone detection.

I'm too lazy to write it all in bbcode but I'll give you the gist of it.
It works because the days since 2000 block is in gmt, the timezone in the uk.
You can manually calculate days since 2000, take the difference, multiply by 24 and round to the nearest quarter. This gives you the gmt timezone, e.g. -5 for us east (or -4 in dst).
You would probably figure out why to round if you thought of it carefully, but as for why to the nearest quarter not nearest half, blame Nepal for having a quarter hour offset from India's timezone.
If you want the exact code for manually calculating days since 2000, you can go to my project Custom Date Countdown and find the my block calculate days since 2000.
Helpful

Last edited by WsDanzel (March 15, 2025 11:14:51)

The_Cool_Scratch_Guy
Scratcher
100+ posts

Scratch Workaround Guide VII

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.

Last edited by The_Cool_Scratch_Guy (March 25, 2025 02:29:03)

jmdzti_0-0
Scratcher
1000+ posts

Scratch Workaround Guide VII

The_Cool_Scratch_Guy wrote:

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

Last edited by jmdzti_0-0 (July 11, 2025 10:53:17)

The_Cool_Scratch_Guy
Scratcher
100+ posts

Scratch Workaround Guide VII

jmdzti_0-0 wrote:

//higher pitch available on other mods, like turbowarp, but this iss scratch’s limit.

The limit is 500, not 360. See this little demonstration project and you will find that 500 is higher pitched than 360, but anything after that is the same.

jmdzti_0-0 wrote:

set [audio end timestamp v] to ((days since 2000) + (((n)/(86400))/([10^ v] of ((300)/(400))::operators)))

Interesting, I didn't know that was how the pitch effect worked. I thought it was just speed percentage minus 100.

jmdzti_0-0 wrote:

set volume to (0)%

Thanks for the correction
secretuch
Scratcher
100+ posts

Scratch Workaround Guide VII

Does anyone has an idea for the block
Remove sprites fencing:: motion
?
jmdzti_0-0
Scratcher
1000+ posts

Scratch Workaround Guide VII

The_Cool_Scratch_Guy wrote:

The limit is 500, not 360. See this little demonstration project and you will find that 500 is higher pitched than 360, but anything after that is the same.
Thank you, but I don’t think I’ll be changing the script because I don’t know the proportions lmoo.

I wrote:

set [audio end timestamp v] to ((days since 2000) + (((n)/(86400))/([10^ v] of ((300)/(400))::operators)))
You can simplify that to 9/10, I don’t know why I did that.

Last edited by jmdzti_0-0 (July 11, 2025 10:58:07)

The_Cool_Scratch_Guy
Scratcher
100+ posts

Scratch Workaround Guide VII

secretuch wrote:

Does anyone has an idea for the block
Remove sprites fencing:: motion
?

Just use the size hack

remove fencing and go to x:(x position) y:(y position) with size: (size) and costume: (costume [name v])

define remove fencing and go to x:(x) y:(y) with size: (size) and costume: (costume)
switch costume to [a blank costume v]
set size to [big number like 99999]
go to x: (x) y: (y)
set size to (size)
switch costume to (costume)
The_Cool_Scratch_Guy
Scratcher
100+ posts

Scratch Workaround Guide VII

Today we have the revised exponent code:

Typically this was used:

([10^  v] of ((exponent) * ([log v] of (base)::operators)) :: operators)

This is using base 10, scratch also offers base e. But both of these are positive, so negative bases won't work as negative numbers don't have logarithms in positive bases (at least not real ones that would be practical for a scratch project).
To counter this limitation, we multiply the exponent of the base's absolute value by the result's intended polarity, which depends on whether the exponent is even or odd. It looks like this:

([10^  v] of ((exponent) * ([log v] of ([abs v] of(base)::operators)) :: operators) :: operators) * (((2)*<((exponent)mod(2))=(1)>)-(1))
secretuch
Scratcher
100+ posts

Scratch Workaround Guide VII

The_Cool_Scratch_Guy wrote:

secretuch wrote:

Does anyone has an idea for the block
Remove sprites fencing:: motion
?

Just use the size hack

remove fencing and go to x:(x position) y:(y position) with size: (size) and costume: (costume [name v])

define remove fencing and go to x:(x) y:(y) with size: (size) and costume: (costume)
switch costume to [a blank costume v]
set size to [big number like 99999]
go to x: (x) y: (y)
set size to (size)
switch costume to (costume)
What about
change x by () offscreen:: motion
and/or
change y by () offscreen::motion
?
The_Cool_Scratch_Guy
Scratcher
100+ posts

Scratch Workaround Guide VII

secretuch wrote:

What about
change x by () offscreen:: motion
and/or
change y by () offscreen::motion
?
Just replace the got to x y with change x/y by as long as you use those blocks around it that make the size hack work.
jmdzti_0-0
Scratcher
1000+ posts

Scratch Workaround Guide VII

so, uh… for the power with the log method, negative bases don’t work like that. For instance, (-5)² is not -25, but rather 25 (you can calculate this manually), opposed to what the output says. Also, negative bases in general tend to not work, since raising a negative number to any non-integer will usually result in a complex number, for example, (-2)⁰ˑ¹³ is approximately 1.00429 + 0.434596i (according to Wolfram Alpha), but the script returns -1.094294 (which surprisingly is the negative absolute value of 1.00429 + 0.434596i).
_nix
Scratcher
1000+ posts

Scratch Workaround Guide VII

jmdzti_0-0 wrote:

so, uh… for the power with the log method, negative bases don’t work like that. For instance, (-5)² is not -25, but rather 25 (you can calculate this manually), opposed to what the output says.
You're right. I really wonder where that came from, since it's literally “accounted for” as though that *is* how they work, even though… it obviously isn't.

if <(base ::custom-arg) < (0)> then
set [power v] to ((-1) * (power)) // Whyyyy???
end

jdzti_0-0 wrote:

Also, negative bases in general tend to not work, since raising a negative number to any non-integer will usually result in a complex number, for example, (-2)⁰ˑ¹³ is approximately 1.00429 + 0.434596i (according to Wolfram Alpha), but the script returns -1.094294 (which surprisingly is the negative absolute value of 1.00429 + 0.434596i).
That makes sense. I wanted to make sure I wasn't missing something obvious so I tried a couple of digital calculators and yeah, (-3) ** 2.2 [etc] just comes up with a NaN or error. However, short of a method to specifically output two values (real and imaginary), I think it's fair to acknowledge this as a shortcoming of the workaround, right?

Maybe we should acknowledge the limitation right in the code by making the workarounds actually output NaN when the result would be imaginary—as opposed to just giving incorrect output!

if <<(base ::custom-arg) < (0)> and <not <(exponent ::custom-arg) = (round (exponent ::custom-arg))>>> then
set [power v] to ((1) / (0)) // I'm assuming this outputs NaN
stop [this script v]
end

Let know what you think or would recommend, if you have the chance. It's obviously true that we aren't really adding new workarounds to the guide at this time, but I want to make sure ones we do have all work correctly and as expected!

edits are to get around very angry forum filter

Last edited by _nix (April 23, 2025 16:25:33)

ispretty
Scratcher
500+ posts

Scratch Workaround Guide VII

_nix wrote:

jmdzti_0-0 wrote:

so, uh… for the power with the log method, negative bases don’t work like that. For instance, (-5)² is not -25, but rather 25 (you can calculate this manually), opposed to what the output says.
You're right. I really wonder where that came from, since it's literally “accounted for” as though that *is* how they work, even though… it obviously isn't.

if <(base ::custom-arg) < (0)> then
set [power v] to ((-1) * (power)) // Whyyyy???
end

That's because you're putting a negative number into a logarithm, which outputs a complex number. Also, this isn't a good fix, as now (-2)² = -4 when it should be equal to 4. There needs to be a check to see if the exponent is even or odd (see this Scratch Wiki article) for more info.

_nix wrote:

jdzti_0-0 wrote:

Also, negative bases in general tend to not work, since raising a negative number to any non-integer will usually result in a complex number, for example, (-2)⁰ˑ¹³ is approximately 1.00429 + 0.434596i (according to Wolfram Alpha), but the script returns -1.094294 (which surprisingly is the negative absolute value of 1.00429 + 0.434596i).
That makes sense. I wanted to make sure I wasn't missing something obvious so I tried a couple of digital calculators and yeah, (-3) ** 2.2 [etc] just comes up with a NaN or error. However, short of a method to specifically output two values (real and imaginary), I think it's fair to acknowledge this as a shortcoming of the workaround, right?

Maybe we should acknowledge the limitation right in the code by making the workarounds actually output NaN when the result would be imaginary—as opposed to just giving incorrect output!

if <<(base ::custom-arg) < (0)> and <not <(exponent ::custom-arg) = (round (exponent ::custom-arg))>>> then
set [power v] to ((1) / (0)) // I'm assuming this outputs NaN
stop [this script v]
end

Let know what you think or would recommend, if you have the chance. It's obviously true that we aren't really adding new workarounds to the guide at this time, but I want to make sure ones we do have all work correctly and as expected!

edits are to get around very angry forum filter
1 / 0 output Infinity, not NaN (0 / 0 is NaN). Also, this workaround means that (-27)^(1/3) is equal to NaN, which is perfectly acceptable depending on your definition of a root (real root versus first principal root).

Last edited by ispretty (April 24, 2025 12:20:16)

The_Cool_Scratch_Guy
Scratcher
100+ posts

Scratch Workaround Guide VII

jmdzti_0-0 wrote:

so, uh… for the power with the log method, negative bases don’t work like that. ~snip~

_nix wrote:

~snip~

ispretty wrote:

~snip~

I literally just fixed that. Just scroll up about 6 posts.

Edit: even though negative bases and fractional exponents give imaginary numbers that it doesn't give, it does give the same results as Google's calc

Last edited by The_Cool_Scratch_Guy (April 24, 2025 21:23:57)

Powered by DjangoBB