-
Notifications
You must be signed in to change notification settings - Fork 565
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
Conversation
… new validator for this so we can ensure the blocks "using" the variables are referencing the same block that was defined.
…ks/teachertool/variable_validator
…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, |
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.
In the case that a teacher is looking for specific variable names, I think we'd want this to be more than one.
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.
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.
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.
Ah, I see, makes sense.
continue; | ||
} | ||
|
||
const varsUsed = block.getVarModels(); |
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.
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
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.
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
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.
Awesome, thank you!
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.
Looks good!
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
andvariable_get
is that we can ensure the names match, and we can ensure it's checking for multiple variables (sovariable_get
isn't just called X number of times on the same variable, even ifvariable_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.