Skip to content
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

validate say blocks for empty strings #45060

Merged
merged 9 commits into from
Mar 1, 2022

Conversation

mikeharv
Copy link
Contributor

Add validation to check that students have entered some text into say blocks:

image (134)

@mikeharv mikeharv requested a review from a team February 25, 2022 23:23
@mikeharv mikeharv requested a review from a team as a code owner February 25, 2022 23:23
@@ -36,6 +36,29 @@ export const commands = {
return result;
},

// Return true if the specified sprite began speaking
// and the text was not an empty string.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nit: replace "was" with "is" in the new comments in this file. i think it helps clarify at a glance that we only care about the current frame, not anything that previously happened in the program

Comment on lines 53 to 59
let result = false;
for (let i = 0; i < spriteIds.length; i++) {
if (commands.strictSpriteSpeechRenderedThisFrame.call(this, i)) {
result = true;
}
}
return result;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(same comment goes for the for loop in strictAnySpriteSpeaking) i think we can simplify this calculation with .filter. you'll see calculations like this commonly expressed as:

spriteIds
  .filter((_spriteId, index) => commands.strictSpriteSpeechRenderedThisFrame.call(this, index))
  .length > 0;

the end result is the same, but it makes the code more functional (as in "functional programming," not related to functionality) and readable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it! I changed both the functions you mentioned, as well as a couple more that were very similar. Reading up on how you can specify both (element, id) led me to realize there was actually an edge case bug that I also fixed.

getSpriteIds() returns an array of ids. In most cases, the index matches the element, but if a sprite is removed, they stop. We needed to be passing in the element, not the id, to be sure we were checking the right sprites.

strictAnySpriteSpeaks() {
const spriteIds = this.getSpriteIdsInUse();
return (
spriteIds.filter(_spriteId =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, sorry, i used the underscore convention (_spriteId) because i thought it would be an unused variable -- in the previous implementation, i thought we were using index, not ID, but i must've misread it. this variable should be spriteId or just id (when you're iterating over a list of IDs, id is usually sufficient context)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't misread it; there was a bug (see other comment)! I was wondering about this underscore convention. I'll make one last update to rename to id, then assume you're still good to approve.

Copy link
Contributor

@maddiedierker maddiedierker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a comment about variable naming, but this looks great once that's addressed!

@mikeharv mikeharv merged commit 4d29d83 into staging Mar 1, 2022
@mikeharv mikeharv deleted the validate-empty-string-say-blocks branch March 1, 2022 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants