T.Hodd: Thanks for pointing this out, these are exactly the sort of things I forget about. One problem I'm having at the moment is getting it to be able to put the string from the read() into the shop class as this requires 9 arguments. This could be done by specifying which part to read for each section and then converting to shop, but this'll be tricky for unkown lengths. Already added this to the project planning page as it'll be critical for mod support.
Yes, mods will be so much easier with this done.
In my game, I've used json and python can convert json to objects directly. Then you just need one argument to your monster or shop class and that is the json parsed object.
you can init your json with this:
def loadjson(filename):
with open(filename) as jsonfile:
jsondata = json.load(jsonfile)
return jsondata
... load the data as: self.moninfo = jsonInit.loadjson("resources/data/creatures.jsn")
... this is the constructor for the monster class:
def __init__(self, parameters):
self.parameters = dict(parameters)
... and this is creation of the monster itself:
player = Monster(self.moninfo[PLAYERCREATURE], self)
(yes, player is the monster too ;)
You also need to create few methods for checking the paramaters in the object, like getparameter which will load it from the dictionary, etc. And you need a good discipline in checking the optional parameters so your game won't crash, as python is dynamically referenced.
I'm not a good pythoner, but it worked for my game. However better to do it soon, as you won't have to refactor so much code then.