完整的代码在这里:http://pastebin.com/gG4JLNsX
这是minimal, complete, verifiable example:
import random
def newGame():
curveSetup()
printStatistics()
def curveSetup():
global curve
curve = random.randint(12,35)
global lvl
lvl = 1
def printStatistics():
global expMax
expMax = (lvl*curve)
global lvl
print "Character Level: "+str(lvl)
newGame()
每当我运行我的程序时,我都会遇到一个错误
Warning (from warnings module):
File "D:\Code\PyRPG.py", line 64
global lvl
SyntaxWarning: name 'lvl' is used prior to global declaration
有人知道怎么修吗?我已经尝试了所有的方法,我在这里查看了类似的问题,在声明变量本身是全局变量之前,它们都是Python 3或定义的“x”。在定义“x”之前,我已经声明它是全局的,因此我不知道这有什么问题。
编辑:我在开始时也定义了lvl=1,但它根本不会改变任何东西。我已经在curveSetup()函数中定义了lvl,它比其他函数运行得更早。
目前没有回答
相关问题 更多 >
编程相关推荐