-
Notifications
You must be signed in to change notification settings - Fork 30
Add support for "when timer greater than" #130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for "when timer greater than" #130
Conversation
// Find triggers which match conditions | ||
let matchingTriggers = []; | ||
for (let i = 0; i < this.spritesAndStage.length; i++) { | ||
const sprite = this.spritesAndStage[i]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting quirk about the old code I noticed: spritesAndStage
is actually a getter which returns a new array every time it's called 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Who would ever write such a thing 🙄
Right now it looks like the trigger is timer-specific. Could it be better to simply have a That way you could trigger when loudness is greater than some number, but also when other conditions are true. |
I thought about that--I was kinda worried there's some reason Scratch itself hasn't just implemented that. It seems that Scratch previously wanted to implement a "when touching" block but ran into some issues--for instance, a script running in parallel that messes with the predicate you're testing for, which technically makes logical sense but is very unintuitive behavior. |
Okay, that makes sense. I am on board with the current choice then. 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Behavior now looks correct to me :)
Resolves part of #122.
This PR adds support for "edge-activated" triggers, so named because they evaluate a predicate every step (e.g. "is the timer greater than N?") and trigger their script on the rising edge (when the predicate changes from
false
totrue
).Trigger predicates/options can now be functions (which are passed the current target) as well as values. This is necessary because the input to a "greater than" block is actually droppable and can contain arbitrary scripts. For codegen purposes, it may be easier to have the function take no arguments and just bind the
this
value to the current target, but that seems jankier.