1

I'm following the tutorial here for using Python2 to interact with Minecraft Pi. Everything is fine up until the "Blocks as Variables" section. Here is my code:

from mcpi import minecraft
from time import sleep

mc = minecraft.Minecraft.create();

dirt = block.DIRT.id

But running this code gives the error for the dirt line:

NameError: name 'block' is not defined

How do I fix this?

2

The error is in the raspberrypi.org example. It's missing an import. Add the following line and your code should work fine:

from mcpi import block

Not the answer you're looking for? Browse other questions tagged or ask your own question.