Hardware Reference
In-Depth Information
Try moving your player to a new location and running the program again. Check the
coordinates displayed on the Python Shell: these should now have changed to reflect
your player's new position. You can use this little program at any time if you want to
confirm the coordinates of a position in the Minecraft world.
A variable is a name for a location in the computer's memory. You can store new
values in variables at any time in your program, and you can read back the values
and display them or use them in calculations. Think of a variable as being a bit like
the memory button on a calculator.
Tidying Up Your Position Display
Before you move on and do more with your Minecraft programs, you can improve the
output of your player position to make it easier to understand. Having three separate
lines of output every time you display the position takes up a lot of space; it would be
nice to have all three parts of the player position on a single line, like this:
x=10 y=2 z=20
To do that, follow these steps:
1. Modify your whereAmI.py program by removing the three print() state-
ments and replacing them with this single line:
print("x="+str(pos.x) +" y="+str(pos.y) +" z="+str(pos.z))
2. Save your program again by selecting File Save, from the Editor menu, and
then run it by clicking Run Run Module. See how the output has improved—
now it is all on one line!
DIGGING INTO THE CODE
In your new version of the whereAmI.py program, a little bit of extra magic
took place, which I need to explain.
In Python, print() will display anything you put in the brackets, and the out-
put will be displayed on the Python Shell. You have already used different ways
of displaying information with print() . Now you can examine them a little
further. Look at this example:
print("hello")
continued
 
Search WWH ::




Custom Search