Discuss Scratch
- Discussion Forums
- » Suggestions
- » Replace when [ v] > (10) block
- jokebookservice1
- Scratcher
1000+ posts
Replace when [ v] > (10) block
They both would have to check the condition every frame refresh, why would one be more efficient than the other? Just wondering
- HoofEMP
- Scratcher
100+ posts
Replace when [ v] > (10) block
They both would have to check the condition every frame refresh, why would one be more efficient than the other? Just wondering
I read on the Scratch Wiki that “forever if” (cut) generated a few ms less lag than the workaround, so wouldn't condensing all of that into one block generate even less lag? My logic is probably flawed.
- LemonComputer
- Scratcher
100+ posts
Replace when [ v] > (10) block
Support.
Maths competition! Jobs include ‘information giver’, ‘artist’, ‘animator’ and ‘music player’! https://scratch.mit.edu/projects/137008562/
- Falcon1234567
- Scratcher
20 posts
Replace when [ v] > (10) block
I think it should be
not
but still, support.
when <> ::events ::hat
not
when <> is true ::events hat
but still, support.
Last edited by Falcon1234567 (Oct. 25, 2016 08:09:07)
- Alberknyis
- Scratcher
1000+ posts
Replace when [ v] > (10) block
They both would have to check the condition every frame refresh, why would one be more efficient than the other? Just wondering
I read on the Scratch Wiki that “forever if” (cut) generated a few ms less lag than the workaround, so wouldn't condensing all of that into one block generate even less lag? My logic is probably flawed.
Just ran a test between
when [timer v] > (0.1)and
forever
if <(timer) > [0.1]> then
end
end
Turns out the second is faster, by about 60 milliseconds.
Also, I've said this like 103,294 times, something being faster by “a few milliseconds” affects the project you're making just as much as me going to the beach many times affects my chance of being shot by a dog with a gun in its mouth. Sure, it's something, but that doesn't mean it's worth considering.
Last edited by Alberknyis (Oct. 25, 2016 11:32:03)
stop [all v] ::stack
- jokebookservice1
- Scratcher
1000+ posts
Replace when [ v] > (10) block
60 ms is 2 frames – quite a difference.
Anyway, this shows it is more accurate. Try the test with a “wait until” bock and I think (again, just a prediction) that it will be as inaccurate as a hat block.
Anyway, this shows it is more accurate. Try the test with a “wait until” bock and I think (again, just a prediction) that it will be as inaccurate as a hat block.
Last edited by jokebookservice1 (Oct. 25, 2016 11:37:53)
- Alberknyis
- Scratcher
1000+ posts
Replace when [ v] > (10) block
60 ms is 2 frames – quite a difference.
Anyway, this shows it is more accurate. Try the test with a “wait until” bock and I think (again, just a prediction) that it will be as inaccurate as a hat block.
How I ran the test:
Speed calculator:
set [a v] to [0]
reset timer
wait until <(a) = [1]>
set [time v] to (((timer) - (0.1)) * (1000))
Test 1:
when [timer v] > (0.1)Result: About 33.44 ms
set [a v] to [1]
Test 2:
foreverResult: About 1.38 ms
if <(timer) > [0.1]> then
set [a v] to [1]
end
end
Test 3:
foreverResult: About 1.28 ms
wait until <(timer) > [0.1]>
set [a v] to [1]
end
stop [all v] ::stack
- HoofEMP
- Scratcher
100+ posts
Replace when [ v] > (10) block
60 ms is 2 frames – quite a difference.
Anyway, this shows it is more accurate. Try the test with a “wait until” bock and I think (again, just a prediction) that it will be as inaccurate as a hat block.
How I ran the test:
Speed calculator:set [a v] to [0]
reset timer
wait until <(a) = [1]>
set [time v] to (((timer) - (0.1)) * (1000))
Test 1:when [timer v] > (0.1)Result: About 33.44 ms
set [a v] to [1]
Test 2:foreverResult: About 1.38 ms
if <(timer) > [0.1]> then
set [a v] to [1]
end
end
Test 3:foreverResult: About 1.28 ms
wait until <(timer) > [0.1]>
set [a v] to [1]
end
(redacted)
Last edited by HoofEMP (Nov. 5, 2016 18:40:21)
- Alberknyis
- Scratcher
1000+ posts
Replace when [ v] > (10) block
Hey hey hey, something tells me we should *blame* the Scratch Team and not the suggestion after all, they all should run at about the same speed (unless I'm misinformed)Post 10
(removed by moderator - please keep it polite) , that's a huge difference. I no longer support my own idea.
Last edited by Paddle2See (Oct. 26, 2016 07:37:46)
stop [all v] ::stack
- TheLogFather
- Scratcher
1000+ posts
Replace when [ v] > (10) block
@Alberknyis:
Unfortunately, the timings you get are not comparable in any sensible way, due to the way the Scratch execution engine schedules loop and hat block processing.
In the case of the “when timer” hat block (and any other such hat block), these only get checked first thing after each screen refresh (unless in turbo mode), which is every 1/30th second – hence the times of ~33ms.
In the case of loops and wait until, if there is nothing happening that (potentially) changes something on-screen, then it all gets run as if in turbo mode – hence the times of ~1ms.
However, if you placed a “go to x: 0 y: 0” block in the forever loop (or any other loop running concurrently with it) then Scratch will throttle the loop speed to 30x per second (unless you run in turbo), and you'll be back to times of ~33ms…
Basically, you're not really doing anything more than timing screen refresh at the moment with your “when timer” block.
Unfortunately, the timings you get are not comparable in any sensible way, due to the way the Scratch execution engine schedules loop and hat block processing.
In the case of the “when timer” hat block (and any other such hat block), these only get checked first thing after each screen refresh (unless in turbo mode), which is every 1/30th second – hence the times of ~33ms.
In the case of loops and wait until, if there is nothing happening that (potentially) changes something on-screen, then it all gets run as if in turbo mode – hence the times of ~1ms.
However, if you placed a “go to x: 0 y: 0” block in the forever loop (or any other loop running concurrently with it) then Scratch will throttle the loop speed to 30x per second (unless you run in turbo), and you'll be back to times of ~33ms…
Basically, you're not really doing anything more than timing screen refresh at the moment with your “when timer” block.
Last edited by TheLogFather (Oct. 26, 2016 18:24:41)
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 - - - -
- - - - 3D Text - - - - - - Simple shapes - - - Controllable structures - - - On the ground - - - - - - In space - - - -
- Alberknyis
- Scratcher
1000+ posts
Replace when [ v] > (10) block
In the case of the “when timer” hat block (and any other such hat block), these only get checked first thing after each screen refresh (unless in turbo mode), which is every 1/30th second – hence the times of ~33ms.
… Dayum. I was wondering what was going on with the *coincidental* 33 ms delay. So in most (a lot of) circumstances they'd go at pretty much the same speed?
stop [all v] ::stack
- TheLogFather
- Scratcher
1000+ posts
Replace when [ v] > (10) block
Yes, quite. … Dayum. I was wondering what was going on with the *coincidental* 33 ms delay. So in most (a lot of) circumstances they'd go at pretty much the same speed?
However, the scripts for hat blocks get appended to the list of active scripts, and then it goes through the currently active scripts and executes, up until the next yield (end of loop, or a wait, etc.), each one.
That means the hat block will start its execution after all of the scripts that were already active have reached their yield points.
In that sense I guess it means these previously active scripts will have had a chance to ‘get in there’ with a relevant test before the hat block script starts up… (If there happens to be an intensive script that runs for a while during this refresh, then the hat block could be delayed for some time. So, a script that is scheduled to run before such an intensive script could ‘catch’ the condition earlier than the hat block script.)
However, it all rather depends on knowing exactly how the various scripts within a sprite, and across sprites, get ordered for execution, and ‘engineering’ the script execution order to take advantage of the timing.
Last edited by TheLogFather (Oct. 27, 2016 12:24:28)
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 - - - -
- - - - 3D Text - - - - - - Simple shapes - - - Controllable structures - - - On the ground - - - - - - In space - - - -
- Discussion Forums
- » Suggestions
- » Replace when [ v] > (10) block