Programmers everywhere warn to not use global variables. I try to design that way myself, but I'm coming into an issue where I think I'm reaching outside my field of knowledge - which is admittedly pretty shabby.
I'm making a controller utility in Python. Originally, the idea was to make something that will display battery level, since that's not accessible to us but is shown in the game bar and can be gotten programmatically. I've done that, using pygame as the window source.
I'm using a package called XInput-python. Right now, I'm only tracking connect, disconnect and button events, but I want to handle stick and triggers as well. The problem is that I want the tts to announce when you move the stick about halfway. It should say left stick or right stick. I haven't decided yet if I want to deal with left stick left, left stick up, etc. But it is definitely possible within that package. There should also be a threshold so that if you say, cross x -0.50000 then x -0.49999, it doesn't retrigger.
Since the events come in so rapidly, it just overwhelms the speech, which is not what I want. So I had the idea to run it through a function called handle_sticks() which would check the values, announce a message, but then set one of the elements in a tuple to True. There would be four. One for each stick, and one for each trigger.
Where I run into trouble is getting around this concept without using global variables. There needs to be a way to keep track of the state of this tuple between function calls. If I return the tuple, then pass it back into the function that creates it in the first place, it'll just get overwritten.
So how can I deal with this without using global variables. I'll paste the code as it stands right now, since I am not overly protective of it, and this can then be a way to gauge feedback from the things that I've done but could be done better, plus hopefully, an answer to my original question.
Click here to view the code, the password is bunnies.