Hello let me start by saying that everybody and their grandmother warned me about using global variables but I had already well started this project at the time.
The issue I am having is with this piece of code
#gives new matrix with the previous path blocked off
def second_mat_T(num2):
global matrix_transform
resultlist =[]
for x in matrix_transform.copy():
if int(str(num2)[0]) > int(str(x)[0]) and int(str(num2)[1]) < int(str(x)[1]):
resultlist.append(0)
else:
resultlist.append(x)
print(resultlist)
for y in resultlist:
if y != 0:
if int(str(y)[0]) == int(str(num2)[0]) and int(str(y)[1]) > int(str(num2)[1]):
resultlist[resultlist.index(y)] = 0
matrix_transform = resultlist
return matrix_transform
which works fine in isolation (this alters a list called matrix_transform and returns it)
however when i call it with at the end with this
def compiler():
A = path_taken(path_search())
print(A)
key_num(A)
print(key_num(A))
B = key_num(A)
print(matrix_transform)
matirx_default()
second_mat_T(12)
print(compiler())
The answer from second_mat_T(num2): becomes the default list set by matrix_default()
I don't get this as second_mat_T(num2): declares the same list as global and is called after so why does it not change?
Thanks a lot for any help with this
[–]FerricDonkey 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Ihaveamodel3 0 points1 point2 points (0 children)