我试图弄清楚如何从外部python文件更改mValue的值。这是我的代码,我不太清楚如何处理这个问题。
game.py
mValue= 0
gHome = GUI_Button()
gHome.lGui('sGui_hotbar.png', 0, 40, 50, 50, 0, 2, 1, 2)
gMove = GUI_Button()
gMove.lGui('sGui_hotbar.png', 0, 100, 50, 50, 0, 0, 1, 0)
while True:
gHome.uGui(lm, mX, mY, mValue)
gMove.uGui(lm, mX, mY, mValue)
sprite_classes.py
class GUI_Button(Sprite):
def lGui(self, file, x, y, w, h, fx1, fy1, fx2, fy2):
Sprite.load(self, file, x, y, w, h, fx1, fy1, fx2, fy2)
self.originX = x
self.originY = y
def uGui(self, mouseDown, mouseX, mouseY, money):
if self.clicked:
self.sFC = self.sF2
money += 1
else:
self.sFC = self.sF1
Sprite.update(self, mouseDown, mouseX, mouseY)