I'm trying to make a game where there's a town with a bunch of residents, and your interactions with them are determined by traits each is assigned, rather than any pre-scripted dialogue specifically for each individual character. I realized going in that I might need to learn a bit of python, and I have been doing so, but there's a really basic coding mechanic that I haven't come across yet. I don't know the correct terminology for it, so I'm just going to have to explain it longhand.
I'd previously had this working by defining a Person class with python and just declaring each as a variable, eg:
Code: Select all
guy01 = Person('Gary','Smith',44,'Blacksmith',['short-tempered','single father','tough','honest'])
gal01 = Person('Jane','Jones',27,'Baker',['patient','funny'])
Now, this was fine, but I realized as I worked on it that it would be much easier if I could have everything read from a tab-delimited text file that I export from an Excel spreadsheet. So I found out how to do this, I'll include the code here just for clarity, or if anyone might find it useful:
Code: Select all
def parse_csv(filename):
f = file(config.gamedir + "/data/" + filename)
rv = [ ]
for l in f:
l = l[:-1]
rv.append(l.split('\t'))
f.close()
return rv
In other programming languages I've fiddled with - probably Flash or JavaScript or both, they sort of blur together for me - you could take data and stick it into a variable name dynamically, sorta like like:
_root["person "+i] = Person([whatever array is necessary])
And as part of a loop where i is each successive pass, you'd end up with a bunch of people objects named person1, person2, person3, etc. I want to be able to do that.
Does this make sense to anyone? I feel like I've written a lot to ask a simple question and may have nevertheless failed to communicate it properly. Hope it's clear enough. Lemme know if it isn't.