Microsoft MakeCode

I can't pass a lambda to on_button_event in Python

Why can’t I pass a lambda to controller.player1.on_button_event for the function to run?

This doesn’t work:

controller.player1.on_button_event(ControllerButton.LEFT, ControllerButtonEvent.PRESSED, lambda: character.set_image(img("""
        . . . . . . . . . . . . . . . .
        . . . . f f f f f f . . . . . .
        . . . f 2 f e e e e f f . . . .
        . . f 2 2 2 f e e e e f f . . .
        . . f e e e e f f e e e f . . .
        . f e 2 2 2 2 e e f f f f . . .
        . f 2 e f f f f 2 2 2 e f . . .
        . f f f e e e f f f f f f f . .
        . f e e 4 4 f b e 4 4 e f f . .
        . . f e d d f 1 4 d 4 e e f . .
        . . . f d d d e e e e e f . . .
        . . . f e 4 e d d 4 f . . . . .
        . . . f 2 2 e d d e f . . . . .
        . . f f 5 5 f e e f f f . . . .
        . . f f f f f f f f f f . . . .
        . . . f f f . . . f f . . . . .
    """)))

Or this:

controller.player1.on_button_event(ControllerButton.LEFT, ControllerButtonEvent.PRESSED, lambda: console.log("hi"))

Or this:

game.on_update_interval(500, lambda: console.log("hi"))

All of them give me

Argument of type '{ TODO: any; }' is not assignable to parameter of type '() => void'.
Cannot find name 'Lambda'.

when I hover my mouse over the red squiggly lines.

Am I using lambda in-correctly because this version doesn’t support using lambda like this? This should be valid syntax in vanilla Python (3).

Definitely looks like a bug! Would you mind filing this on github?

Sorry for the late reply, was eating dinner and contemplating how to word it, but I got it done!

2 Likes