-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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 variables to dropdown menu, and more goodies #3102
Add variables to dropdown menu, and more goodies #3102
Conversation
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.
Left miscellaneous comments (one bug which definitely needs work).
Just another thing to note - I haven't tested this, but I'm pretty sure that, if you rename a variable which is selected in the dropdown, it will not be updated in that dropdown. Of course, the user would expect it to be, since variable dropdowns do update. That'll take a little more work in this PR if wanted.
@@ -110,6 +110,75 @@ export default function (vm) { | |||
return [[myself, '_myself_']].concat(spriteMenu()); | |||
}; | |||
|
|||
const variablePropertyMenu = function (thisValue) { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
[costumeName, 'costume name'], | ||
[size, 'size'], | ||
[volume, 'volume'] | ||
]; |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
]; | ||
|
||
const sourceBlock = thisValue.sourceBlock_; // This is the <shadow>. | ||
const ofBlock = sourceBlock && sourceBlock.parentBlock_; // This is the "of" block. |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
src/lib/blocks.js
Outdated
const target = vm.runtime.getSpriteTargetByName(objectName); | ||
if (target) { | ||
// Pass true to skip the stage: we only want the sprite's own local variables. | ||
const variableNames = target.getAllVariableNamesInScopeByType('', true); |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
Travis is having a whole bunch of errors - they probably have to do with scratch-blocks not being updated by this PR. There aren't any errors when I do |
…ed by a block (This commit diff best viewed with -w / ?w=1.)
The getAllVariableNamesInScopeByType returns variable names in an arbitrary (unsorted) order. Use scratchBlocksUtils.compareStrings to sort the result using the same method as other places where variables are sorted (see scratchfoundation/scratch-blocks#1521).
Hmm... Tricky problem with this is that existing Scratch 3.0 projects are broken. 2.0 projects adjust properly, but 3.0 projects lose the data previously stored in the PROPERTY field (which is now an input). (Note the console message |
@towerofnix, sorry for the long delay in reviewing this pull request. I'm afraid since a side effect of this PR is that the property menu of the |
@kchadha No worries. Any thoughts on the code which would be needed to implement this, then? The only other dropdown which is not-droppable and dynamically-filled is the variable/list/message dropdowns, but these are all implemented in ways which rely on accessing variables either specific the currently selected sprite or shared across all sprites. (The code for doing so is in scratch-blocks, which indeed does not have access to other sprites the same way the GUI and VM do.) And I know the Scratch Team is not obligated to, but I request that you consider the paragraph I've quoted below. And, by necessity, I request that it be considered soon (i.e. not be backlogged): making the block droppable after the release of 3.0 will break many 3.0 projects, but making it before will break virtually none, due to so few existing.
|
PS, several existing projects would be broken by not making the input droppable. The fact is that unless scratchfoundation/scratch-vm#1030 - a rather colossal task nobody has gotten anywhere seriously far with since its creation in April - is resolved, any blocks which use hacked arguments will break. Several projects do place arguments inside the "of" block; while I don't have any statistic, it's one of the more common uses of hacked arguments that I've seen. Not making the input droppable means these projects will break. |
@towerofnix, that's a great question, as you pointed out, it's definitely not straightforward given the current examples we have of making block menus dynamic. @picklesrus and I looked into this a bit and the official blockly way to do it is to replace the "options" part of the JSON block definition for the property field with a function that populates the menu options. From just a preliminary look at what it would take to do this, there are definitely some tricky bits and also some architectural issues to figure out on our end, especially since the function will have to take in information about what is selected on the other menu in the block. Looking at the original issue that this PR was trying to fix, I noticed that it does not have a help wanted label on it. I am inclined to close this and the related scratch-blocks PRs since the implementation for the issue fix will require some more thought. |
Resolves
Resolves scratchfoundation/scratch-vm#1425: "For this sprite only" (local) variables are now shown in the dropdown.
Resolves scratchfoundation/scratch-blocks#1418: This is unintentional (a side-effect of reusing the basic code for the object dropdown), but the property dropdown now accepts blocks.
Fixes backdrop options (backdrop name, backdrop #) from being shown in sprite dropdowns, and vice versa (x position, etc, in stage dropdown). I couldn't spot an issue for this one.
Depends on scratchfoundation/scratch-blocks#1712. Merge this one after that one!
Proposed Changes
This PR reworks how the
PROPERTY
dropdown of the "(property) of (object)" sensing reporter block works internally, allowing for the changes listed above.Note that the property dropdown now accepts blocks. That's not intentional - it's just that I reused most of the code for the object dropdown. I'm not sure how to make it a "square" dropdown (i.e. one which does not accept blocks). In my opinion, letting it accept blocks is a good thing anyways, since it allows and encourages dynamically accessing variables (or even ordinary attributes, like "x position" and "direction"). The argument against it is that an unfamiliar user might try placing a block such as "volume" into that dropdown, and then be confused as to why it always returns 0. But I think that any such user would quickly figure out the error they made; I think the functional benefit greatly outweighs the minor potential difficulty.
That said, I'm okay with making the input not accept blocks, if it'd be preferred to merge this sooner and keep discussion about that topic in its particular issue.
There are some comments I have on specific parts of the code. I'll leave those in a review of the PR.
Reason for Changes
These are nearly all bug-fixes / enhancements which make the Scratch 3.0 editor match 2.0.
Test Coverage
I haven't added any new unit tests, but this has been tested manually: