I have been helping a student troubleshoot their code on the Unit 7 project without success. When they call their methods to draw various elements, the program fails, but when tested individually the methods work. I asked them to include debug statements to verify that the methods were receiving the correct attributes and they were. Here is the student’s workaround:
I think I’ve found a solution. It’s not the most efficient, and I had to create a basically empty class for it to work, but at least it works, especially since my original attempt doesn’t seem to be possible. I was looking through documentation and forum posts and couldn’t find an explanation for my issues, but I have a theory. I think the Scene drawing commands are constrained to the class in which they are called, so calling drawScene() inside of StatsScene causes the drawing executions to exist within StatsScene and not TheaterRunner, so when I called Theater.playScenes() inside of the main method, Theater couldn’t reach the Scene commands that I called in StatsScene.
My fix compiles TitleScene and the Themes into an array which is then traversed inside of TheaterRunner, and each object’s respective drawScene() methods are called. This is what the empty class that I mentioned is for; Scene doesn’t have a drawScene method, so I needed a parent class that had the method so the various subclasses could be compiled into a single array and drawScene() could be called on each element. Then Theater’s play() method is used, as it takes a Scene array.
Their solution works, but it feels like there are some undocumented limitations to the Scene methods.