Skip to content

Fixed error causing only the last button on the launcher to be called

Bailey Andrew requested to merge fix-scope-error into master

[Medium-Priority; Bug Fix!]

I discovered a quite insidious error inside the launcher! Basically, in python, this:

func_list = []
out = []
for i in range(5):
    func_list.append(lambda: out.append(i))
for func in func_list:
    func()
print(out)

Will print 44444 rather than 01234! Because lambdas capture by reference rather than by value I guess and since python lets its for-loop index variables persist after the loop ends, this error is fairly well-hidden and hard to spot! This basically caused the way the launcher handles buttons to not quite work in the expected way, leading to a non-negligible amount of confusion on my end!

For future reference, the trick around this is to do (lambda i: lambda: out.append(i))(i) rather than lambda: out.append(i) since the outer lambda will copy the variable by value ;) (Unless that value is mutable, then this might not work and you'd probably need to do something like (lambda i: lambda: out.append(i))(i.copy()) - just a guess, I may be wrong on that)

Edited by Bailey Andrew

Merge request reports