我正在为一个流行的 MMORPG 制作一个自动化脚本。我收到以下错误:
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
startFishing()
File "C:\Python27\DG\RS\RS bot.py", line 56, in startFishing
if inv == "full":
NameError: global name 'inv' is not defined
我在下面详细介绍了我的功能。
def isMyInventoryFull():
s = screenGrab()
a = s.getpixel((1173,591))
b = s.getpixel((1222,591))
c = s.getpixel((1271,591))
d = s.getpixel((1320,591))
if a == b == c == d:
print "Inventory is full! Time to go back home."
inv = "full"
print inv
else:
print "Inventory is not full."
inv = "notfull"
time.sleep(3)
def startFishing():
mousePos((530,427))
leftClick()
time.sleep(0)
inv = 'full'
openUpInventory()
isMyInventoryFull()
if inv == "full":
time.sleep(0.01)
else:
isMyInventoryFull()
mousePos((844,420))
rightClick()
time.sleep(1)
问题是,我在“isMyInventoryFull”函数中定义了“inv”,但是它没有发现“inv”已经被定义?我肯定在这里遗漏了一些东西,有人可以帮忙吗?