Discuss Scratch

Seth_Zaw
Scratcher
100+ posts

When <> (Events Block)

when <> :: events

¡Aprendamos español con los Alfabetons!
In my new series, you will cover genders of nouns, important and useful phrases, conjugating verbs and adjectives, regular and irregular words, and more, in Spanish!
Click here to get started!
Visit the Official Alfabetons Website: https://alfabetons.com
Seth_Zaw
Scratcher
100+ posts

When <> (Events Block)

Example use:
when <(score) = [10]> :: events
say [Yay!]


when <touching [fire v]?> :: events
say [Oh no! Fire!] for (1) secs
hide

¡Aprendamos español con los Alfabetons!
In my new series, you will cover genders of nouns, important and useful phrases, conjugating verbs and adjectives, regular and irregular words, and more, in Spanish!
Click here to get started!
Visit the Official Alfabetons Website: https://alfabetons.com
monstermash3
Scratcher
1000+ posts

When <> (Events Block)

Duplicate, also this used to exist but was removed due to not responding to the stop button.

(Swallowed by an evil kumquat who was just taking a walk in the neighborhood of evil kumquats when they saw a garage sale where they bought a plate which they used to eat but they discovered that it leaked and they went to get their money back but the sale was over so they went in the house but the door was locked so they got their key but it didn't fit so they went home to use the key on the right door which was their own door and then they decided to swallow a signature for no reason.)
TheLogFather
Scratcher
1000+ posts

When <> (Events Block)

Before this gets closed, I'll just note that you can use the “when timer” hat block to emulate a “when” block:

So this:
when <test goes here> :: events
do stuff... :: grey
…is done like this:
when [timer v] > ((timer)+((1) - ((2)*<test goes here>)))
do stuff... :: grey

The above script will execute once at each point that the test becomes true (i.e. once at the start if it's true then, and each time after it changes from false to true).


It's also possible to emulate a “while” hat block (which runs all the time that the test is true) – but I won't get into that here (since it's not great to have a script that can potentially keep running over and over even after the project stops).


EDIT: Please note, though… I wouldn't really recommend using this method – it's already the case that Scratchers tend to have loads of checks for things running within loads of different separate forever loops, most of which don't need to be happening for much of the time the project is running. So having yet more tests (potentially expensive touching tests) that are running even when a project is stopped…

Last edited by TheLogFather (Aug. 10, 2018 13:55:14)


Siggy the Kumquat slayer:
Main account: DadOfMrLog –– Frameworks for basic pen-rendered 3D in scratch (see studio). Examples:

- - - - 3D Text - - - - - - Simple shapes - - - Controllable structures - - - On the ground - - - - - - In space - - - -

TheAdriCoolManDude
Scratcher
1000+ posts

When <> (Events Block)

Workaround:
forever
if <...> then
...
end
end


red_king_cyclops
Scratcher
500+ posts

When <> (Events Block)

TheLogFather wrote:

Before this gets closed, I'll just note that you can use the “when timer” hat block to emulate a “when” block:

So this:
when <test goes here> :: events
do stuff... :: grey
…is done like this:
when [timer v] > ((timer)+((1) - ((2)*<test goes here>)))
do stuff... :: grey

The above script will execute once at each point that the test becomes true (i.e. once at the start if it's true then, and each time after it changes from false to true).


It's also possible to emulate a “while” hat block (which runs all the time that the test is true) – but I won't get into that here (since it's not great to have a script that can potentially keep running over and over even after the project stops).

Here is the easier workaround:
when green flag clicked
broadcast [when v]
when I receive [when v]
wait until <test goes here::grey>
do stuff... ::grey
wait until <not <same test from earlier goes here::grey>> //Remove this if you want a sort-of while loop.
broadcast [when v] //Remove this if you want the when to be able to run only once.

Last edited by red_king_cyclops (Aug. 10, 2018 13:37:37)


2+2=4
2*2=4
2^2=4
2^^2=4
2^^^2=4
2^^^^2=4

I see a pattern.
ShinigamiBlacky
Scratcher
100+ posts

When <> (Events Block)

both dont work when stop button pressed…
LogFathers does :P

Last edited by ShinigamiBlacky (Aug. 10, 2018 13:23:16)

TheLogFather
Scratcher
1000+ posts

When <> (Events Block)

ShinigamiBlacky wrote:

LogFathers does [work when stop pressed] :P
Which is not necessarily a good thing, mind – it's not great to have Scratch continually perform tests that could be expensive (e.g. touching tests), even when the project is not actually running…

Given how it's already the case that Scratchers wildly overuse the (bad) technique of doing such tests all the time in lots of separate very short forever loops (rather than trying to combine into as few main loops as possible – preferably only one – and only do checks at the specific times they need to while the project is running), it's probably not a good idea to add yet another easy way for Scratchers to make their projects descend into the realm of sluggish lag.

(I meant to mention this in my post above, but I was a bit rushed doing other things at the same time, and forgot…)
(OK, now added it as a disclaimer in post above…)

Last edited by TheLogFather (Aug. 10, 2018 13:57:49)


Siggy the Kumquat slayer:
Main account: DadOfMrLog –– Frameworks for basic pen-rendered 3D in scratch (see studio). Examples:

- - - - 3D Text - - - - - - Simple shapes - - - Controllable structures - - - On the ground - - - - - - In space - - - -

monstermash3
Scratcher
1000+ posts

When <> (Events Block)

TheAdriCoolManDude wrote:

Workaround:
forever
if <...> then
...
end
end
You would also have to use the reset-timer trick for a perfect emulation of the removed block, otherwise the stop sign would prevent it.

(Swallowed by an evil kumquat who was just taking a walk in the neighborhood of evil kumquats when they saw a garage sale where they bought a plate which they used to eat but they discovered that it leaked and they went to get their money back but the sale was over so they went in the house but the door was locked so they got their key but it didn't fit so they went home to use the key on the right door which was their own door and then they decided to swallow a signature for no reason.)

Powered by DjangoBB