So I am trying to have a file that has a bunch of object in it that looks like this:
<class 'oPlayer.oPlayer'>,123,4,<class 'CommonObject.Wall'>,175,4,<class 'CommonObject.Wall'>,25,654,<class 'CommonObject.Wall'>,1,123,<class 'CommonObject.Wall'>,55,87
(No newlines for splitting purposes)
The file holds the object name, x, and y coordinate. (Basic info) But I'm not 100% sure how to create the objects from the file. Here is what I have:
def loadRoom(self, fname):
# Get the list of stuff
openFile = open(fname, "r")
data = openFile.read().split(",")
openFile.close()
# Loop through the list to assign said stuff
for i in range(len(data) / 3):
# Create the object at the position
newObject = type(data[i * 3])
self.instances.append(newObject(int(data[i * 3 + 1]), int(data[i * 3 + 2])))
The objects in the file all take two arguments, x and y. So I'm also confused on how that would work. What I did was grab the list with all the split strings, (Which I displayed, it came out correct. No \n's) then I loop through the list (sort of) to set all the data. I assumed that type
would return the object, but it doesn't.
Any help with said topic is very appreciated.