我試圖讓機器人從一個坐標移動到目標坐標以“收集披薩”然后將披薩移動到一組新的坐標但是出現以下 NonType Eroor,我不知道這意味著什么。這是我的移動代碼:
def move(self):
for c in [0,1]:
if (self.coordinates[c] < self.target[c]):
if ((self.target[c] - self.coordinates[c]) < self.max[c]):
self.velocity[c] = (self.target[c] - self.coordinates[c])
else:
self.velocity[c] = self.max[c]
elif (self.coordinates[c] > self.target[c]):
if ((self.coordinates - self.target[c]) < self.max[c]):
self.velocity[c] = -(self.coordinates[c] - self.target[c])
else:
self.velocity[c] = -self.max[c]
else:
self.velocity[c] = 0
self.coordinates[c] = self.velocity[c]
這是錯誤訊息:
TypeError Traceback (most recent call last)
<ipython-input-140-00c07d25f390> in <module>()
33 robot.activity = 'idle'
34
---> 35 robot.move()
36 ecosystem.update()
37 print(ecosystem.hour)
<ipython-input-136-c31d02f30645> in move(self)
36 def move(self):
37 for c in [0,1]:
---> 38 if (self.coordinates[c] < self.target[c]):
39 if ((self.target[c] - self.coordinates[c]) < self.max[c]):
40 self.velocity[c] = (self.target[c] - self.coordinates[c])
TypeError: 'NoneType' object is not subscriptable
這是機器人代碼
class Robot:
model = 'robot1'
def __init__(self):
self.coordinates = [1,2,0]
self.kind = 'Robot'
self.max = [1,1,0]
self.velocity = [1,1,0]
self.status = 'on'
self.name = 'robotJL'
self.activity = 'idle'
self.target = None
self.age = 0
self.serviced = 0
self.soc = 600
self.capacity = 600
self.service = 0
self.size = 500
self.damage = 0
self.color = 'green'
self.shape = 'triangle'
self.on_arena = 0
self.service = 0
self.weight = 50
self.payload = 100
self.cargo = None
self.distance = 0
self.energy = 0
uj5u.com熱心網友回復:
我想,您的robot物件(coordinates或target)的屬性之一是None,您應該檢查它。
uj5u.com熱心網友回復:
這意味著目標坐標或當前坐標包含 None 值,因為它不允許您使用 self.coordinates[c] 或 self.target[c]。將這兩個值列印出來會讓您清楚地了解。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/402203.html
