Hardware Reference
In-Depth Information
X2 = 20
Z2 = 20
HOME_X = X2 + 2
HOME_Y = 10
HOME_Z = Z2 + 2
2. Now you are going to time how long your player is in the field for, and to do this
you need another variable which you can call inField . It will store the number
of seconds that the player has been in the field for and it will be used to decide
when your player has been in the field for too long! Again, you only need to add
the parts shown in bold:
rent = 0
inField = 0
3. Next, you need to add a line of code that adds 1 to the inField variable if the
player is in the field. To do this, add the code shown in bold:
if pos.x>X1 and pos.x<X2 and pos.z>Z1 and pos.z<Z2:
rent = rent+1
mc.postToChat("You owe rent:"+str(rent))
inField = inField+1
4. Now you're going to add an else statement, so that the program resets the
timer to zero if the player is not in the field. Make sure you get the indentation
correct on the else statement so that Python knows exactly what you mean.
You will learn about the else statement in a moment as well as what the # sym-
bol is used for but, for now, just type in the code shown in bold:
mc.postToChat("You owe rent:"+str(rent))
inField = inField+1
else: # not inside the field
inField = 0
5. Finally, you need to add some additional lines of code at the end of the program
to catapult the player into the sky and out of the field if he is in the field for more
than three seconds. Gravity will make him fall to the ground and he will have to
run back into the field again. This code goes right at the end of your program.
he if must be indented one level because it is part of the while True loop,
and the statements that belong to the if must be indented two levels from the
far left of the program. Type the following:
if inField>3:
mc.postToChat("Too slow!")
mc.player.setPos(HOME_X, HOME_Y, HOME_Z)
 
Search WWH ::




Custom Search