我一直在尝试创建一个脚本,该脚本在字典中获取列表,并编辑它们以创建类似网格的东西。我正在尝试使变量等效于列表中值的索引,但错误表明数据中没有这样的属性。我试图调用方法,而不是检索属性,但这就是机器认为我想要做的。
我正在使用 Python 3.5 的 32 位版本。
这是脚本。我已经在有问题的行中添加了评论。
#Map Generation Script
GRID = {
1 : [1,1,1,1,1,1,1,1,1,1],
2 : [1,1,1,1,1,1,1,1,1,1],
3 : [1,1,1,1,1,1,1,1,1,1],
4 : [1,1,1,1,1,1,1,1,1,1],
5 : [1,1,1,1,1,1,1,1,1,1],
6 : [1,1,1,1,1,1,1,1,1,1],
7 : [1,1,1,1,1,1,1,1,1,1],
8 : [1,1,1,1,1,1,1,1,1,1],
9 : [1,1,1,1,1,1,1,1,1,1],
10 : [1,1,1,1,1,1,1,1,1,1]
}
def usepen(x):
Areaedit = GRID[godpenx]
Areaedit[godpeny] = x
GRID[godpenx] = Areaedit
def makeshapeline(tile, length):
for item in GRID: #I know this isn't indented properly
for unit in GRID[item]:
if unit == tile:
locpenx = GRID.index(item) #offending line
locpeny = GRID[item].index(tile)
anglea = randrange(0,1)
angleb = randrange(0,1)
while anglea + angleb == 0:
anglea = randrange(0,1)
angleb = randrange(0,1)
for nump in length:
locpenx += anglea
locpeny += angleb
if locpenx or locpeny > 9:
break
GRID[locpenx[locpeny]] = tile
usepen(0)
makeshapeline(0, randrange(1,8))
for item in GRID:
print (GRID[item])