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

Teacher Tool: Variable Usage Validator #9994

Merged
merged 8 commits into from May 3, 2024

Conversation

thsparks
Copy link
Contributor

@thsparks thsparks commented May 1, 2024

This adds a new validator which can check if variables are both defined and used. The key difference between this and "block-exist" checks for variable_set and variable_get is that we can ensure the names match, and we can ensure it's checking for multiple variables (so variable_get isn't just called X number of times on the same variable, even if variable_set defines X unique variables, and so on...).

You can optionally filter by name, but we don't expose this currently in any criteria. You can also used nested validation to ensure a variable is set to something specific (like pick random), but again, we don't have any criteria that currently use this.

… new validator for this so we can ensure the blocks "using" the variables are referencing the same block that was defined.
…and a count. For now just flatten it in runValidatorPlan itself to prep for recursive calls...
"template": "Uses at least ${count} variables",
"docPath": "/teachertool",
"description": "The program creates and uses at least this many user-defined variables.",
"maxCount": 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

In the case that a teacher is looking for specific variable names, I think we'd want this to be more than one.

Copy link
Contributor Author

@thsparks thsparks May 3, 2024

Choose a reason for hiding this comment

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

We would, but this criteria doesn't have a name parameter. That's functionality in the validator but we don't expose it yet. Hence the limit of 1 for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see, makes sense.

continue;
}

const varsUsed = block.getVarModels();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you tell me a bit or point me to the reference for getVarModels? For some reason, I'm having a hard time finding it in the blockly docs. I found https://developers.google.com/blockly/reference/js/blockly.block_class.getvars_1_method.md

Copy link
Contributor Author

Choose a reason for hiding this comment

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

getVars just returns string of variable ids, but getVarModels returns full objects with type information (which we don't set) alongside the name and a function to get the id: https://developers.google.com/blockly/reference/js/blockly.variablemodel_class

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome, thank you!

Copy link
Contributor

@srietkerk srietkerk left a comment

Choose a reason for hiding this comment

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

Looks good!

@thsparks thsparks merged commit 387ee3a into master May 3, 2024
6 checks passed
@thsparks thsparks deleted the thsparks/teachertool/variable_validator branch May 3, 2024 22:25
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