Skip to content

Including distance sensor in a while block and Play Melody is selected, compilation fails #9

Open
@jharris1993

Description

@jharris1993

Given the following code:

input.onButtonPressed(Button.A, function () {
	
})
function drive () {
    basic.showIcon(IconNames.Happy)
    music.playMelody("C D E F G A B C5 ", 500)
    basic.pause(200)
    while (true) {
        gigglebot.driveStraight(gigglebotWhichDriveDirection.Forward)
    }
    Avoid()
}
input.onButtonPressed(Button.B, function () {
    basic.pause(200)
    drive()
})
input.onLogoEvent(TouchButtonEvent.Pressed, function () {
    gigglebot.stop()
    basic.pause(200)
    control.reset()
})
function Avoid () {
    basic.showIcon(IconNames.Sad)
    music.playMelody("C5 B A G F E D C ", 500)
    drive()
}
// gigglebot.stop()
basic.pause(200)
basic.showIcon(IconNames.Yes)

This code, as written, will compile.

If you replace the function "drive" with the following:

function drive () {
    basic.showIcon(IconNames.Happy)
    music.playMelody("C D E F G A B C5 ", 500)
    basic.pause(200)
    while (gigglebot.distanceSensorTestForObstacle(gigglebotInequality.Farther, 300)) {
        gigglebot.driveStraight(gigglebotWhichDriveDirection.Forward)
    }
    Avoid()
}

The compilation fails.

The difference is the condition in the while loop.

I do not see any obvious syntax errors.

Note that removing EITHER the while conditional, OR the play statement will allow compilation to proceed. It is only when BOTH are present that the compilation fails.

This has been confirmed on the micro:bit support site at https://support.microbit.org/support/tickets/52863

Please advise.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions