Hardware Reference
In-Depth Information
FIGURE.8-3 Creating random numbers to give your block friend an air of
unpredictability
3. Add the random module to the import statements at the top of the program
(the code in bold ):
import mcpi.minecraft as minecraft
import mcpi.block as block
import mcpi.minecraftstuff as minecraftstuff
import math
import time
import random
4. Add a 1 in 100 random number test to change the block's mood to "hadenough"
when the block is "sad" :
elif blockMood == "sad":
if distance <= 1:
blockMood = "happy"
mc.postToChat("<block> Awww thanks. Let's go.")
if random.randint(1,100) == 100:
Search WWH ::




Custom Search