Discuss Scratch

HarmlessOstrich
Scratcher
100+ posts

a every () seconds block!

we need an
Every () seconds

it would be a C block but i dont know how to make that it would repeat a code every () seconds
MDCCCLXVII
Scratcher
1000+ posts

a every () seconds block!

HarmlessOstrich wrote:

it would be a C block but i dont know how to make that
every (1) seconds {
} :: control loop
HarmlessOstrich
Scratcher
100+ posts

a every () seconds block!

MDCCCLXVII wrote:

HarmlessOstrich wrote:

it would be a C block but i dont know how to make that
every (1) seconds {
} :: control loop

thx
fdreerf
Scratcher
1000+ posts

a every () seconds block!

A very crude implementation would just be:

forever
...
wait (time ::grey) secs
end

and I believe that this would be more accurate:

forever
if <((timer) mod (time ::grey)) = [0]> then
...
end
end

and if you want to make your limited time on this wretched planet worth it:

forever
if <((((days since 2000) - ([floor v] of (days since 2000))) * (86400)) mod (time ::grey)) = [0]> then
...
end
end
fdreerf
Scratcher
1000+ posts

a every () seconds block!

Fus_ion wrote:

https://scratch-mit-edu.ezproxyberklee.flo.org/projects/382631312/editor
That's very cool but I don't believe that project has what the suggestor wanted.
sportfan999
Scratcher
1000+ posts

a every () seconds block!

Fus_ion wrote:

https://scratch-mit-edu.ezproxyberklee.flo.org/projects/382631312/editor
i n t e r e s t i n g
But yeah, use the workarounds that @fdreerf wrote, especially the “days since 2000” block one because the “days since 2000” block is just dope.
chrdagos
Scratcher
500+ posts

a every () seconds block!

what if the code in the C-loop takes longer to execute than the number of seconds that of which was defined. more specifically, what would happen if i made this:
every (5) seconds{
wait (8) secs
} :: control
would it wait until the code in it finished executing or would it stop execution and go to the beginning of the code, repeating this proccess?
NanoPIex
Scratcher
500+ posts

a every () seconds block!

chrdagos wrote:

what if the code in the C-loop takes longer to execute than the number of seconds that of which was defined. more specifically, what would happen if i made this:
every (5) seconds{
wait (8) secs
} :: control
would it wait until the code in it finished executing or would it stop execution and go to the beginning of the code, repeating this proccess?
I think then we`d have a problema.
CST1229
Scratcher
1000+ posts

a every () seconds block!

chrdagos wrote:

what if the code in the C-loop takes longer to execute than the number of seconds that of which was defined. more specifically, what would happen if i made this:
every (5) seconds{
wait (8) secs
} :: control
would it wait until the code in it finished executing or would it stop execution and go to the beginning of the code, repeating this proccess?
I think running a broadcast script twice in quick succession cancels the script and restarts it, so I think the same thing will apply for this.
Besides, you can just use a wait block in a forever script.
NanoPIex
Scratcher
500+ posts

a every () seconds block!

CST1229 wrote:

chrdagos wrote:

what if the code in the C-loop takes longer to execute than the number of seconds that of which was defined. more specifically, what would happen if i made this:
every (5) seconds{
wait (8) secs
} :: control
would it wait until the code in it finished executing or would it stop execution and go to the beginning of the code, repeating this proccess?
I think running a broadcast script twice in quick succession cancels the script and restarts it, so I think the same thing will apply for this.
Besides, you can just use a wait block in a forever script.
No support due to this two-block workaround:

forever
wait (...) secs
end
Tunde123
Scratcher
1000+ posts

a every () seconds block!

NanoPIex wrote:

No support due to this two-block workaround:

forever
wait (...) secs
end
Agreed. No support because of the quoted text above.

Last edited by Tunde123 (Dec. 5, 2020 16:32:40)

gosoccerboy5
Scratcher
1000+ posts

a every () seconds block!

Tip: with ScratchBlox syntax, you can use a curly bracket to denote a c loop or whatever. Here's an example:
repeat until broadcast [message v] received? {
...
} :: control
This turns into
repeat until broadcast [message v] received? {
...
} :: control

Anyways, I'd have to say no support because of the workaround. You can execute code and wait a few seconds in a forever loop, detect when timer mod (x) is 0, you can mess with broadcasts, or you can get fancy with the days since 2000 block. If custom c blocks ever get added, it'll make it even easier to work around this. It's a good suggestion though
NanoPIex
Scratcher
500+ posts

a every () seconds block!

Tunde123 wrote:

NanoPIex wrote:

No support due to this two-block workaround:

forever
wait (...) secs
end
Agreed. No support because of the quoted text above.
lol
Maximouse
Scratcher
1000+ posts

a every () seconds block!

No support because it isn't much harder to do this without a special block.
mybearworld
Scratcher
1000+ posts

a every () seconds block!

no support, as of the workaround people posted.
NanoPIex
Scratcher
500+ posts

a every () seconds block!

NanoPIex wrote:

Tip: with ScratchBlox syntax, you can use a curly bracket to denote a c loop or whatever. Here's an example:
repeat until broadcast [message v] received? {
...
} :: control
This turns into
repeat until broadcast [message v] received? {
...
} :: control

Anyways, I'd have to say no support because of the workaround. You can execute code and wait a few seconds in a forever loop, detect when timer mod (x) is 0, you can mess with broadcasts, or you can get fancy with the days since 2000 block. If custom c blocks ever get added, it'll make it even easier to work around this. It's a good suggestion though
gosoccerboy5
Scratcher
1000+ posts

a every () seconds block!

I feel like you quoted me and replaced the quote with your name.
HarmlessOstrich
Scratcher
100+ posts

a every () seconds block!

gosoccerboy5 wrote:

I feel like you quoted me and replaced the quote with your name.
They DID!
fdreerf
Scratcher
1000+ posts

a every () seconds block!

chrdagos wrote:

what if the code in the C-loop takes longer to execute than the number of seconds that of which was defined. more specifically, what would happen if i made this:
every (5) seconds{
wait (8) secs
} :: control
would it wait until the code in it finished executing or would it stop execution and go to the beginning of the code, repeating this proccess?
I think that the block would do what it says: execute the code every X seconds. So, in this example, every 5 seconds it will wait 8 seconds, and there will be some overlap where two scripts are running at once. I believe my latter two workarounds accomplish this.

Powered by DjangoBB