Ex43/45 stuck on making engines

Hi, I’ve been chipping away at LPTHW for a while and have recently been able to tackle it at least a bit on most days. Not surprisingly ex43/OOP was a challenge but I’ve enjoyed sorting through the pieces. However I feel like I’m stuck with making engines that successfully run through a game/classes without continuously creating new instances of classes (e.g to be able to keep track of points between classes/definitions). I’ve deconstructed the finite state engine provided in ex43 (print, print, deconstructing each line…) but haven’t been able to get a different kind of engine running for ex45.

Does anyone have examples to share of simple engines they’ve created/come across? Thanks!

Well, first up you definitely want to copy my Engine and Map and then modify it to get an understanding of it before you try your own version.

After that, well, I think it’s fine if you’re creating a ton of objects since Python is an object oriented language. That has different design implications, but it’s fine. One design problem is if you want people to go into a room, change something, then come back, you can’t if you’re making a new object every time they enter.

So, how do you stop making new objects? In the code where you get the object for the room, rather than creating a new instance, pull it from a place where one instance is stored. That can be a global or a class variable.