Hardware Reference
In-Depth Information
continued
The following line creates a list with three items in it (the x, the y and the z coor-
dinates of a block you have just placed):
coordinate = [pos.x, pos.y-1, pos.z]
By putting values between the [ ] brackets, you are creating the list with val-
ues already in it, rather than creating an empty list. You could have done the
same like this:
coordinate = []
coordinate.append(pos.x)
coordinate.append(pos.y-1)
coordinate.append(pos.z)
Later, when your program retrieves the coordinates of a block to delete, it pops
off a list (of coordinates) from your bridge list:
coordinate = bridge.pop()
The list that is stored in the coordinate variable has three items inside it:
coordinate[0] is the x position of the block; coordinate[1] is the y posi-
tion of the block; and coordinate[2] is the z position of the block.
Figure 4-5 shows what this “list of lists” actually looks like.
FIGURE.4-5 A bridge is a list of coordinates, and each coordinate is a list.
Python actually has a number of different variable types for storing collections
of items, in addition to the lists that you have just used. Professional Python
programmers would probably use a feature called a tuple in this program for storing
the coordinates. I didn't want to introduce too many concepts here in one go. If you
like, you can do some research on the Internet about tuples, and find out how they
are different from lists and what additional benefits they bring to a Python program.
Search WWH ::




Custom Search