scratchfoundation / scratchfoundation/scratch-blocks

Custom dropdowns (specify your own list of options)

Open
#1,867 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request
Dominant language
JavaScript
Stars
2.8k
Forks
1.6k
Avg merge
4h 51m
Merged PRs (30d)
12

Description

Feature request!

Often times I create custom blocks that take an input that is basically a flag with several options. For example, suppose I have two behaviors I want to make into custom blocks - one which sets a "MP" value of every character with HP > 0 to its maximum value, and one which sets it to zero. Now since these both share a lot of behavior (specifically, looping over the list of characters and acting on each one who has HP > 0), it's simplest for me to make this into one custom block, and have the caller specify which action should be used. That custom block definition would look like this:

A lengthy custom block definition that follows the specification above, in particular checking if an "action" input is "restore" or "clear" and deciding what to do with the MP value based on that.

However, typing in those values is tedious, and prone to error - what if I make a typo? In a sense, it makes my custom block "un-Scratch-like": it makes my programming rely on typed syntax, already an inconvenience, and therefore makes it vulnerable to syntax errors!

Here's another example: Suppose I define a sort-of "object" system, similar to what you saw in the example above. I make a list of character names, and I create a custom block which changes the value of a given field on the character with a given name. This might look something like the following:

A custom block definition: "define set (name) 's field (field) to (value): set index to (item # of (name) in (Characters → Names)". Then, for each valid field value (HP, MP, Max MP), it checks if the passed field value is equal to that, then performs "replace item (index) with (value)" on the appropriate list.

Of course, it's again clear that the "field" input can take on one of several values, and that this value changes the behavior of the custom block.

In cases like these, the problem of un-Scratch-ness could be avoided by making use of a simple new feature: the ability to define custom dropdowns. The concept is quite simple: the dropdown has a list of options that you, the creator of the custom block, specify.

The UI for how that should look needs discussion, but I have one idea: You press a button to add the dropdown input to the custom block in the "Make a Block" dialog. Then the input is automatically focused. Then, instead of transforming into an input which you type in to rename the input, it shows a menu beneath it containing several options: name of the input, type of the dropdown, and if the type is "custom", preview of the dropdown, which can be edited to add the options you want. (Of course, clicking the dropdown from the block in the "Make a Block" dialog would open that form again.)

Part of the reason I suggest this idea is that other options for inputs would fit in very nicely as well. For example, suppose we used this UI for every kind of input. Then there could be another row, beneath the name row, for setting the default value of the input - again, making the user's own custom blocks more similar to and as useful as real Scratch blocks.

Thoughts? I'm happy to discuss and clarify any of my ideas here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files, tests, or entry points are named. Start by reviewing the proposed custom dropdown behavior and the Make a Block dialog discussion, then establish the UI and option-list requirements; done should mean custom block creators can define dropdown options without typing each value manually.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.