Recently I have been working on a game and I am using pygbag to convert it to HTML so that it can be played on a web browser. When I build the python files and run them, the game works as expected. However, when I used the pygbag command inside the command line, and then went to localhost:8000
(the development port in which the game would be temporarily posted), the audio worked, but I encountered a black screen. I went to localhost:8000#debug
, which would show me what error was occuring, and it gave this error: https://imgur.com/a/y1sH9h0
It came from the import_assets()
method of the Player()
class. The method in question is:
def import_assets(self):
self.animations = {}
for index, folder in enumerate(walk("graphics/player")):
print(index)
if index == 0:
for subfolder in folder[1]:
self.animations[subfolder] = []
else:
for file_name in folder[2]:
path = folder[0].replace("\", "/") + "/" + file_name
surf = pygame.image.load(path).convert_alpha()
key = folder[0].split("\")[1]
self.animations[key].append(surf)
This method is used to import the “left”, “right”, “down”, and “up” facing walking animations of the player. In total there are 4 “groups”, one for each direction (R L U D), and each “group” contains 4 walking animation frames. So there are 16 player images that need to be imported. It would be tedious to import all 16 images individually, so I coded a function to do it using a for loop. The walk()
function is os.walk()
. All the images are added to the self.animations variable, which is a dictionary. The keys are “up”, “down”, “left”, and “right”, and the values associated with the keys are lists containing each frame of the walking animation in that direction.
The line that is giving an error is the second last line:
key = folder[0].split("\")[1]
This error only occurs when I open the pygbag test server at localhost:8000
. If I run the code normally using Python on my computer, the code works perfectly fine as expected and no error occurs. Could someone please help me With this issue? I apologize if this question was written wrongly, this is my first StackOverflow question.
I tried going to localhost:8000#debug to see the error, and found the error given previously. I also tried incorporating ALL classes into ONE main.py file and that didn’t work either.
Tanish Shukla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.