Discuss Scratch

dxscmfrt
Scratcher
26 posts

"When flag clicked" block and start broadcasts

Would it be better (performance and/or file size-wise) to use a when flag clicked block in every sprite or to have this instead?:

when gf clicked // in one sprite
broadcast [start v]

when I receive [start v] // in every other sprite
...
because I've seen many people do this “so there's only one green flag block”, which is why I'm wondering
Wahsp
Scratcher
1000+ posts

"When flag clicked" block and start broadcasts

I mean I'm pretty sure I've had scripts that just don't activate sometimes (although that might mostly be with sprites that have multiple green flags within them) and I think I've seen that happen to other people so this might help with that

Personally I think I'd be too lazy to do that every time even though it's not that big of a hassle lol

Anyway I'm not sure if this answers anything because I'm not too well versed in the technical aspects of stuff, but I'm sure someone will come along soon who will have an exact answer on the effects of this

Last edited by Wahsp (Aug. 4, 2021 03:55:41)

awesome-llama
Scratcher
1000+ posts

"When flag clicked" block and start broadcasts

It's not a performance benefit, it's to give better control to how the project gets started up, particularly to prevent the “click the green flag twice” glitch.

If you have a bunch of green flag clicked blocks, the issue can arise where one starts before another resets important variables.

A very simple example is this:

when green flag clicked
wait until <(score) > [10]>
say [you win] for (2) secs
when green flag clicked
set [score v] to [0]

The order these scripts run can't be controlled, if the first one starts before the second resetting one, then you will get the “you win” to run.

This can be fixed by combining scripts but sometimes you want to have all the variables in one place or some other scripts completely running first. Then, you can use a broadcast technique:

when green flag clicked
set [score v] to [0]
...
broadcast [start game v]

I always do it with my projects so I do have some great examples of it in use:

This is for a flight sim. Ignore the purple blocks, I've made custom blocks coloured that way because I prefer it. The red rectangle at the bottom highlights the broadcast that starts up the project. Look at how much stuff I need to reset before everything else. The blue rectangles are for other variable resetting scripts to get started up first too.

Last edited by awesome-llama (Aug. 4, 2021 04:00:33)

Chiroyce
Scratcher
1000+ posts

"When flag clicked" block and start broadcasts

dxscmfrt wrote:

Would it be better (performance and/or file size-wise) to use a when flag clicked block in every sprite or to have this instead?:
Yes, not in terms of performance, but in terms of reduced glitches, as awesome-llama said. It's good practice to do so since scratch isn't multithreaded, some green flags may be executed before others, leading to what's called as a race condition. So using broadcasts is better.
dxscmfrt
Scratcher
26 posts

"When flag clicked" block and start broadcasts

awesome-llama wrote:

It's not a performance benefit, it's to give better control to how the project gets started up, particularly to prevent the “click the green flag twice” glitch.

If you have a bunch of green flag clicked blocks, the issue can arise where one starts before another resets important variables.
Okay, first of all, I'm not making a game; variables and having multiple green flags are not the problem.
This can be fixed by combining scripts
The issues, for me, mainly happen when I'm playing around with sprite layering (usually using the go forward/backward block) and those problems can't be fixed that easily using only script combining or broadcasts.

But I got one of the answers I wanted, so thanks anyway. I still want to know whether it significantly affects project file size or not, though.

Ignore the purple blocks
[offtopic]i know why the custom blocks are purple, bold of you to assume i'm new to scratch[/offtopic]
Chiroyce
Scratcher
1000+ posts

"When flag clicked" block and start broadcasts

dxscmfrt wrote:

i know why the custom blocks are purple, bold of you to assume i'm new to scratch
um awesome-llama is using an extension to change the color of the blocks, in reality, it's this —
dxscmfrt
Scratcher
26 posts

"When flag clicked" block and start broadcasts

Chiroyce wrote:

dxscmfrt wrote:

i know why the custom blocks are purple, bold of you to assume i'm new to scratch
um awesome-llama is using an extension to change the color of the blocks, in reality, it's this —
yes, i know they're using an extension, i'm just saying i know why they prefer it to be purple. again, bold of you to assume i don't know anything.
this is getting way off topic aaa

Last edited by dxscmfrt (Aug. 4, 2021 07:07:53)

Powered by DjangoBB