私は Star Wars Galaxies のエミュレーターに取り組んでおり、使用しているスクリプト言語は Jython です。defの外で変数を定義する方法がわかりません。ここにエラーがあります..
UnboundLocalError: ローカル変数 'actorFunds' が割り当て前に参照されました
そしてコード(不要なものをたくさん切り取る...クラスはありません)
commandArgs = ""
commandLength = 0
globalTarget = SWGObject
globalActor = CreatureObject
tipAmount = 0
actorFunds = 0
totalLost = 0
bankSurcharge = 0
def run(core, actor, target, commandString):
global globalTarget
global globalActor
global commandArgs
global commandLength
global tipAmount
global bankSurcharge
global actorFunds
global totalLost
globalTarget = target
globalActor = actor
commandArgs = commandString.split(" ")
commandLength = len(commandArgs)
tipAmount = commandArgs[0]
bankSurcharge = int(0.05) * int(tipAmount)
actorFunds = actor.getBankCredits()
totalLost = int(tipAmount) + bankSurcharge
.......
return
def handleBankTip(core, owner, eventType, returnList):
if eventType == 0:
if int(totalLost) > globalActor.getBankCredits():
globalActor.sendSystemMessage('You do not have ' + str(totalLost) + ' credits (surcharge included) to tip the desired amount to ' + globalTarget.getCustomName() + '.')
return
if int(tipAmount) > 0 and int(actorFunds) >= int(totalLost):
return
return
私がactorFundsにたどり着くと、エラーが表示されます...
長い間検索しましたが、理由がわかりません。「これ」を使ってJavaと同じくらい簡単だったらいいのに...