2 questions: Moving multiple blocks in editor and micro:bit simulator keyboard control

Sorry for the 2 noob questions, which may be answered before, but I am unable to locate:

  1. Is it possible in the editors somehow to select and move multiple blocks of code around, like a marquee tool or holding down a key while selecting several blocks or something, for moving around on the canvas?
    This need emerges especially when switching back to block based code from text based, and everything has been tossed around seemingly at random… :wink:

  2. Are there any ways to activate keyboard controls for the micro:bit simulator?.
    I have tried most keys on the keyboard, so I am assuming the answer might be no, but this could be useful e.g. for simulating functionality like holding button A while pressing button B and vice versa and etcetera.

unfortunately the answer for both is not today

1 Like

Hi
The standard BBC microbit library allows for python based as console input() functions.
Will ms microbit make code cloud based coding support this same feature in the future? (Or does it already?)

@emory55 not sure what you’re referring to there. can you give me some example code in python that you want to recreate in makecode maybe?

Your question triggered a flash of memory from a long time ago, @emory55.

Might you mean something like this?:

(A very good idea for a useful functionality IMO, and some (presumably) related mentions other places, too:
https://forum.makecode.com/t/microbit-extension-that-adds-to-the-simulator-and-debugger/19465/5
https://github.com/microsoft/pxt-microbit/issues/5110)

Maybe there are some synergies for the micro:bit and the sought after “input() from console” with the anticipated keyboard input of text, too?

Sure, this python code runs on the simulator at:
https://python.microbit.org/v/3
The code, in particular, involves the Python function input(), which is standard i/o.

As far as I know, the MS Microbit can’t do the following code:
guess = int (input(“Enter your number :”))

It can, however, handle the print() functions.

#Example source code file for the python.microbit.org/v/3 simulator:
# This code works on https://python.microbit.org/v/3
# Imports go at the top of the file
from microbit import *
from random import *
import music


# Code in a 'while True:' loop repeats forever
while True:  
    # randint gets a random whole number inclusively 
    # between the two values given 
    guessMyNumber = randint(1,100)
    print("")
    print("You have 9 chances to guess my number between 1 and 100: ") 
    guessCount = 9
    while (guessCount > 0):
        # print to the console how many guesses left
        print ("Guess # ", guessCount)
        try:
            guess = int (input("Enter your number :"))
        except:
            print ("Invalid number. Try again.")
            continue
        if (guess == guessMyNumber):
            print("You win!")
            display.show(Image.HAPPY)
            music.play(music.BA_DING)
            break;
        else:
            #lower the guess count by 1 
            guessCount = guessCount - 1
            #STUDENT TASK - tell the player if the target number is 
            # higher or lower. 
            # In addition, display an up arrow or down arrow
            # on the microbit. (Image.ARROW_N means north, Image.ARROW_S means south)
            if (guess > guessMyNumber):
                display.show(Image.ARROW_S)
                print ("My number is smaller.")
            else:
                display.show(Image.ARROW_N)
                print ("My number is bigger.")
    if (guessCount == 0):
        print("You lose! No more guesses!")
        #STUDENT TASK 2, print to the console what the correct number was.
        #HINT: look at how we print the number of guesses
        print ("The number was: ", guessMyNumber)
        display.show(Image.SAD)
        music.play(music.WAWAWAWAA)
    display.show(guessMyNumber,wait=True)
    display.clear()
1 Like

Apparently. all whitespace gets removed in this forum. Here is png snapshot:

@emory55 if you wrap your code with three back ticks like this:

```
# code goes here
```

then whitespace will be preserved! i’ll edit your first post and fix it.

how does the input function work on the micro:bit? does it accept input from the connected computer? surely the python code hasn’t implemented any way to enter text on the micro:bit itself…

The official micro:bit Python simulator accepts input() via keyboard from the serial console screen…:

Not sure if the physical micro:bit responds the same way for received characters over real serial some way.

But the input() in the simulator console would have some utility, like in @emory55’s program snippet here, debugging etc… (in all editors, not just micro:bit) :wink:

See also: GitHub etc.

UPDATE: The physical micro:bit also receives keyboard characters and has 2-way interaction in the “physical” serial console (there are 2 “serial consoles” - one for the simulator and one for the connected micro:bit) in the IDE / Simulator over both Bluetooth and WebUSB:

Seems like one of the main causes for the need for moving multiple code blocks has been addressed already:

ah, i see! we don’t currently have any plans for doing something like a serial console to the device but it’s an interesting idea. you should file a feature request here:

1 Like

Already filed some years ago (by your boss? - @jacqueline.russell) and brutally closed as “won’t fix”…:

:wink:

…and @eanders made some attempts at a simulator extension for keyboard and mouse, but they were probably more akin to your already produced browser extension and keyboard entry for “ask for string” etc. in Arcade.

So a common theme among some people seems to be a wish for more input possibilities overall (and others have also made comparisons to the official python simulator’s / IDE’s serial consoles earlier) and maybe 2-way console interaction.

But how big the demand is, or if there are any technical synergies between the wishes and different editors, I don’t know. But since the input() function or some ways to get data into a program is a pretty common (educational) theme*, maybe enough to reopen the already filed request above?

*Many curriculums contain loading tables into arrays / data structures, which is a challenge, at least in Arcade, but you had that already very early on in e.g. the “Date Science Editor” MakeCode Lab etc.

@emory55 Makecode doesn’t have a prompt to send information to the micro:bit, but it does support serial commands that can send and receive text. Here’s a simple project that can send and receive text: https://makecode.microbit.org/S88739-49984-72060-76350

There’s a webusb library that you could use to create your own “console” web page: https://github.com/bsiever/microbit-webusb . The demo webpage (here) will print any text the micro:bit sends and has a button to send the word “Test” to the micro:bit. [Note: The demo webpage can only be used if the MakeCode tab is closed or has disconnected from the micro:bit.]. It would be possible to update that example page to have a text field and behave like the Console in the Python editor.

1 Like

Seems like @jacqueline.russell already filed this with a suggested solution with a Blockly plugin recently:

This was filed very early on, but closed as “won’t fix” just recently:

Thanks for the possible work arounds.
I’m teaching Python using Microbit
The official simulator doesn’t have cloud saving like MS Makecode version but it does support the standard input() function which we use for teaching basic IO functionality in Python.

Some the custom workarounds might still work and I appreciate the responses.

1 Like