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

Behaviour for function parameters and event parameters #163

Open
microbit-matt-hillsdon opened this issue Jan 20, 2025 · 3 comments
Open

Comments

@microbit-matt-hillsdon
Copy link
Contributor

The MakeCode project will duplicate the function parameter (text) and event parameter (receivedString) on drag to allow them to be used in the body of the function/event handler. How should this work with keyboard navigation? Copy/paste?

MakeCode project share link

Image

Note in MakeCode these are not global variables available from the toolbox.

@kmcnaught
Copy link

Possible UX approaches (to discuss - I currently have no opinion)

Baseline - these variables are only available via Copy/Paste - this seems like it will probably already work once Copy/Paste is working correctly for variables. i.e. implementation simple. Discoverability is poor, could be confusing.

Make available in the toolbox - in the MakeCode toolbox, the "Radio" category could include the "local" variables as standalone blocks, you just get a warning if they are used them in the wrong place. It's already possible to use them elsewhere, and you get a tooltip warning.

Alternative 1 - the toolbox could offer "Local variables" as an additional category which is populated as appropriate when your cursor is in the scope of the variables, and you've asked to insert/replace a block. This might be confusing as they'd disappear when cursor is outside of scope, and someone using a mix of keyboard/mouse might not be particularly aware of where their cursor is in the moment. But on the plus, it might improve discoverability and avoid the current UX trap of deleting your local variable and not being able to get it back.

Alternative 2 - the flow for "insert oval shaped block" could be more streamlined, and not use the whole toolbox, and be populated with appropriate blocks.

I guess the function parameter example is one that will be shared across different platforms, might be worth checking what other people do?

@microbit-robert
Copy link

Just a quick comment @kmcnaught that the "Make available in the toolbox" option notes that it's already possible to use these parameters elsewhere, however, this is a bug and not the intended behaviour. There's an open issue in pxt-microbit for this. You can observe the intended scoped drag and drop behaviour in the previous version of MakeCode (v6).

@rachel-fenichel
Copy link
Contributor

Blockly creates function parameters as global variables (leading to a different type of confusion).

Scratch has the same behaviour for function parameters (which is what initially inspired this behaviour in MakeCode, I believe). Their variables can only be of types Number, String, or Boolean. A reporter that is used out of its intended scope will always evaluate to the same value for each type--I think that Number evaluates to 0, String to the empty string, and Boolean to false.

This is never really explained in Scratch, I believe. It's a pattern that people just run into and then use. I looked in the Scratch Wiki to see how the Scratchers explain it, but they just skim past it.

Of Kirsty's options, I like Alternative 1 the best.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

4 participants