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

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

Open
jharris1993 opened this issue Apr 29, 2022 · 0 comments

Comments

@jharris1993
Copy link

jharris1993 commented Apr 29, 2022

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.

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

No branches or pull requests

1 participant