I'm working on a emulator for Star Wars Galaxies and the scripting language that we're using is Jython. I'm having trouble figuring out how I define a variable outside the def. Here is the error..
UnboundLocalError: local variable 'actorFunds' referenced before assignment
And the code (cut out a lot that wasn't necessary... There is no class)
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
When I get to actorFunds it provides the error...
I've searched for a long time and can't figure out why. I wish it was as simple as java with a "this"...