Discuss Scratch

New to Scratch
2 posts

How does the Scratch environment thread a HAT-block?

I have a HAT-block
Only direct after changing an input. (for example idx=0, and oldvalue is 1 and curValue is 0), the HAT-block is activated.
However when the I check on breakpoint 01, I notice that every polling cycle this is true.
But the there is not a second HAT-block event.
Only after changing the value again ( 1->0->1) there is a HAT block action.
I looks like that the poller also remembers that he has check a value and keep track when it change again.

In the documentation I can't find a good functional description of the HAT-block in relation with the internal Scratch-poller and the generation af a HAT-block action.


HAT block function
ext.onFallingEdge = function (idx) { //idx is 0
var test = ext.input.isFalling(idx);
if(test) {
console.log(“Falling index= ” + idx) ; //<< breakpoint 01
return test;
ext.input = {
curValues: {},
oldValues: {},
initInputs: function () {
this.curValues.inputs = ; //after update
this.oldValues.inputs = ; //after update

this.oldValues.inputs = this.curValues.inputs;
isRising: function (index) { return ext.input.oldValues.inputs === 0 && ext.input.curValues.inputs === 1; },
isFalling: function (index) { return ext.input.oldValues.inputs === 1 && ext.input.curValues.inputs === 0; },
New to Scratch
2 posts

How does the Scratch environment thread a HAT-block?

It looks like that Scratch keep track of al the HAT-block and services them during an internal poll cycle
The first true evaluation leads to the execution of the following blocks the next true evaluation are blocked.
A false evaluation reset this blocking.
However the code in the HAT-block is evaluated every polling cycle and for every instance of this HAT-block in the Scratch program.

This mechanisme makes it difficult to connect a HAT block with an event.
How to signal that all the instances of a HAT-block has been serviced the event only one time?

Powered by DjangoBB

Standard | Mobile