Discuss Scratch

mcdowels
Scratcher
17 posts

Run a broadcast multiple times per frame?

In a game I'm working on, there is a list of varying length. The game needs to run code for each item in the list. I need precise control over the execution order of scripts so I use a broadcast to call the code at an index in the list, however it appears that if a broadcast is sent in a frame where the same broadcast has already been sent, it cancels out the previous one. meaning the code only runs for the last item in the list. To go through all items in the list would take multiple frames. Because the list could be any length, making a seperate broadcast for each entry doesnt make sense. Based on my testing, using one broadcast and iterating through the list under it is too slow, as the main loop of the game finishes before the list is analyzed. If anyone has more information in this it would be appreciated. Thank you

Last edited by mcdowels (May 5, 2023 17:33:49)

rodper6635
Scratcher
100+ posts

Run a broadcast multiple times per frame?

Can you give me the project?
mcdowels
Scratcher
17 posts

Run a broadcast multiple times per frame?

For an example of the broadcasts cancelling out:

define every frame
set [idx v] to (1)
repeat (5)
broadcast [print idx v]
change [idx v] by (1)

end

when I receive [print idx v]
print (idx)

I believe it would only print “5”, I know that the print block does not exist, but just for demonstration, this is what i've experienced.
rodper6635
Scratcher
100+ posts

Run a broadcast multiple times per frame?

Does “every frame” have “run without screen refresh” checked?
mcdowels
Scratcher
17 posts

Run a broadcast multiple times per frame?

rodper6635 wrote:

Does “every frame” have “run without screen refresh” checked?
yes, and I have tried putting the script under the broadcast received into a run without screen refresh as well.

rodper6635 wrote:

Can you give me the project?
I can try to send an example when I get back to my pc.
rodper6635
Scratcher
100+ posts

Run a broadcast multiple times per frame?

I think that it's because all 5 instances of the “run idx” message run at the same time, are both of these scripts in the same sprite or in different sprites?
mcdowels
Scratcher
17 posts

Run a broadcast multiple times per frame?

rodper6635 wrote:

I think that it's because all 5 instances of the “run idx” message run at the same time, are both of these scripts in the same sprite or in different sprites?
I have tried broadcasting between sprites and in the same sprite, the same thing happens either way.
rodper6635
Scratcher
100+ posts

Run a broadcast multiple times per frame?

mcdowels wrote:

rodper6635 wrote:

I think that it's because all 5 instances of the “run idx” message run at the same time, are both of these scripts in the same sprite or in different sprites?
I have tried broadcasting between sprites and in the same sprite, the same thing happens either way.
I was asking because I wanted to see if
broadcast [ run idx v] and wait
could replace
broadcast [run idx v]
though I guess it would work either way.

Last edited by rodper6635 (May 5, 2023 17:58:29)

10data10
Scratcher
100+ posts

Run a broadcast multiple times per frame?

The broadcast only gets put on the list of scripts to run once time per frame.

Did you need to use a broadcast because multiple sprites are involved?

mcdowels
Scratcher
17 posts

Run a broadcast multiple times per frame?

10data10 wrote:

The broadcast only gets put on the list of scripts to run once time per frame.

Did you need to use a broadcast because multiple sprites are involved?

yes, there are clones of a sprite that need to check collision with another sprite, and the positions of all the clones and the second sprite need to be updated sequentially multiple times per frame. It might be possible to combine the two sprites into one, but I dont have it figured out and it would be much more complicated. Thanks for the info
ggenije
Scratcher
500+ posts

Run a broadcast multiple times per frame?

The broadcast works that way when you call them the scripts which are run by receiving them are run the next frame, and they are not stackable, which means same broadcast could be called only one time per frame.

It's very hard to get up with solution if you don't explain in detail what you do, or even better give us the project link (shared).
It seems there is a simple solution to your problem, but still I can't help you until I see what are you exactly trying to do.
mcdowels
Scratcher
17 posts

Run a broadcast multiple times per frame?

ggenije wrote:

The broadcast works that way when you call them the scripts which are run by receiving them are run the next frame, and they are not stackable, which means same broadcast could be called only one time per frame.

It's very hard to get up with solution if you don't explain in detail what you do, or even better give us the project link (shared).
It seems there is a simple solution to your problem, but still I can't help you until I see what are you exactly trying to do.
I've made another post with more details about this problem https://scratch.mit.edu/discuss/topic/683259/

Last edited by mcdowels (May 9, 2023 00:34:58)

Powered by DjangoBB