Using `include` to bring variables into scope not working

I have answered my own question, having found a bunch of threads on the issue e.g. this one. For my next project I will take the advice of writing everything in functions (though the claim that “The new debugger works like a charm” does not line up with my experience when I tried it back then). For now I’m going to keep putting global everywhere as if my life (or more realistically a deadline) depended on it.