UnboundLocalError, Python

0

Good morning, I'm doing a code, and I've come across this error in my function which belongs to the movement sense of a "car" that moves in a matrix. Therefore, if it is empty, " " , it can be moved but if it encounters a frame | it should cancel the movement .. within this frame is this utf-8 icon, and therefore if it touches it it should return that " you have won ", I leave you an example of the board of which I speak:

def comprueba(t,orientacion,corx,cory,letramov,longitud):
    copia = copy.deepcopy(t)
    anchura = corx + longitud
    if orientacion == 'H':
        if letramov <= ord('Z'):
            comprueba = corx-1
        elif letramov >=ord('a'):
            comprueba = anchura+1
        if comprueba >19:
            retornocomprueba = 0
        else:
            valor = copia[cory][comprueba]

    elif orientacion == 'V':
        if letramov <= ord('Z'):
            comprueba = cory -1
        elif letramov >= ord('a'):
            comprueba = longitud+cory+1
        if comprueba >19:
            retornocomprueba = 0
        else:
            valor = copia[comprueba][corx]

    if valor == u'\u2593' and letramov == 'a':
        retornocomprueba = 2
    else :
        if valor != ' ':
            retornocomprueba = 0
        else:
            retornocomprueba = 1
    return retornocomprueba 

Any solution?

Error:

juega(nvles,puntuaciones)
  

File "C: \ Users \ saul \ workspace \ test \ practice.py", line 241, in plays
  if it checks (t, orientation, corx, cory, letramov, length) == 1:
  File "C: \ Users \ saul \ workspace \ test \ practice.py", line 130, in check
  if value == u '\ u2593' and letramov == 'a':
  UnboundLocalError: local variable 'value' referenced before assignment

    
asked by oxsaulxo 26.03.2017 в 19:53
source

1 answer

0

Although it seems that you have already solved the problem, I can not pass up the opportunity to recommend this talk of the PyConES 2016 that deals with the UnboundLocalError theme:

The closures that moved Spielberg (Víctor Terrón & Pablo Salgado, 2016)

answered by 28.03.2017 в 12:47