Import the library
The first thing in the program tells Pybricks "I want to use the Ranger 8-Way library". Without this line the hub does not know what MBC_LASER8 means, and you get a NameError.
Pick one library (both work the same way; only the import line is different):
- Download the library (save the file and keep its name): MBC_laser8.py (only this sensor) or MBC_sensors.py (the all-in-one library). You picked
MBC_laser8.py. - In Pybricks Code, click "Import a file" in the file area on the left and import it into the same project.
- Do not rename the file, and do not put it in a sub-folder.
- Go back to your main program and type these lines at the very top (marked ① on the right).