Discuss Scratch

sanyn007211
Scratcher
8 posts

Script not running

One of the scripts in my game is meant to wait until the the time is __o'clock then send a broadcast.
when green flag clicked
forever
wait until <(current [minute v]) = [00]>
broadcast [startRound v]
end

The broadcast has over 100 blocks (is that the problem?), but it starts off like this.
when I receive [startRound v]
switch costume to (happy v)
repeat (30 v)
add [] to [questionGivers v]

When I click the green flag, the yellow outline shows around the script but when it hits _o'clock, but the broadcast doesn't start running, and this isn't the first time it's happened. Why is this?
ABC124816
Scratcher
100+ posts

Script not running

sanyn007211 wrote:

One of the scripts in my game is meant to wait until the the time is __o'clock then send a broadcast.
when green flag clicked
forever
wait until <(current [minute v]) = [00]>
broadcast [startRound v]
end

The broadcast has over 100 blocks (is that the problem?), but it starts off like this.
when I receive [startRound v]
switch costume to (happy v)
repeat (30 v)
add [] to [questionGivers v]

When I click the green flag, the yellow outline shows around the script but when it hits _o'clock, but the broadcast doesn't start running, and this isn't the first time it's happened. Why is this?
The problem is, after the broadcast is sent, the current minute is still zero, so when the loop starts over, the wait until will wait 0 seconds before broadcasting the message again. And again, for at least a thousand times. In scratch, when you broadcast a message, then re-broadcast it, the scripts that were running after the first broadcast will stop and start over, so they never manage to run all their code.
Here is a fix for the bug:
when green flag clicked
forever
wait until <(current [minute v]) = [00]>
broadcast [startRound v]
wait until <not <(current [minute v]) = [00]>>
end
The extra wait until will wait until after the o'clock before starting the loop over, at which point the current minute will be 01 and the message won't be broadcast again very soon. Hope this is helpful!

Last edited by ABC124816 (Sept. 23, 2024 16:43:22)

sanyn007211
Scratcher
8 posts

Script not running

ABC124816 wrote:

sanyn007211 wrote:

One of the scripts in my game is meant to wait until the the time is __o'clock then send a broadcast.
when green flag clicked
forever
wait until <(current [minute v]) = [00]>
broadcast [startRound v]
end

The broadcast has over 100 blocks (is that the problem?), but it starts off like this.
when I receive [startRound v]
switch costume to (happy v)
repeat (30 v)
add [] to [questionGivers v]

When I click the green flag, the yellow outline shows around the script but when it hits _o'clock, but the broadcast doesn't start running, and this isn't the first time it's happened. Why is this?
The problem is, after the broadcast is sent, the current minute is still zero, so when the loop starts over, the wait until will wait 0 seconds before broadcasting the message again. And again, for at least a thousand times. In scratch, when you broadcast a message, then re-broadcast it, the scripts that were running after the first broadcast will stop and start over, so they never manage to run all their code.
Here is a fix for the bug:
when green flag clicked
forever
wait until <(current [minute v]) = [00]>
broadcast [startRound v]
wait until <not <(current [minute v]) = [00]>>
end
The extra wait until will wait until after the o'clock before starting the loop over, at which point the current minute will be 01 and the message won't be broadcast again very soon. Hope this is helpful!
Thanks so much!!!

Powered by DjangoBB