I’m doing ok so far. I’ve managed to reduce the code massively. Some snippets of code were a little more complicated but managed to get them ‘for’ looped
So, I’m now trying to take the audio out of the main file. I created a new .py file called audio.py and pasted all the audio data in there with an import upygame at the top of that file.
In the main.py file, at the top it now has:
import upygame as pygame import urandom as random import umachine # For on-screen text import file # Graphics import audio # Audio
Then a little further down I have my interface class which handles audio and screen stuff:
class Interface: def __init__(self): self.x = 0 self.y = 0 ... # Play sfx def playMove(self): g_sound.play_sfx(audio.moveSound, len(moveSound), False)
But now I get the error:
File "main.py", line 125, in playMove NameError: name 'moveSound' isn't defined
As you can see, I’ve tried copying the way you can reference graphics be prepending it with the .py file name, and without, and it doesn’t work. Am I supposed to add something I’m unaware of in the new audio.py file to make the main.py code see it?