def classCreate(self):
self.classChoose = Toplevel(root)
self.classChoose.title('Choose your Class')
self.classChoose.geometry('300x200+300+400')
self.labelChoose = Label(self.classChoose, text="Select the class you wish to be")
self.labelChoose.grid(row=0)
self.listClass = Listbox(self.classChoose, height=4)
self.listClass.grid(row=1)
self.listClass.insert(END,"Warrior")
self.listClass.insert(END,"Brute")
self.confirm = Button(self.classChoose, text="Confirm", command=self.confirm)
self.confirm.grid(row=2)
def confirm(self):
fileClass = open('ClassData.txt','r')
for line in fileClass:
classInfo=line.split(',')
print "Name is:", self.Name
print "This class's stats are:",classInfo
if classInfo[0]==self.listClass.curselection()[0]:
className=classInfo[0]
self.CharHpMax = classInfo[1]
self.CharHpCurrent = classInfo[2]
self.CharMpMax = classInfo[3]
self.CharMpCurrent = classInfo[4]
self.CharStr = classInfo[5]
self.CharDef = classInfo[6]
self.CharMAtt = classInfo[7]
self.CharMDef = classInfo[8]
self.Currentexp=0
self.Requiredexp=10
print "The name of the class is: ",className
print "The Character's max HP is: ",self.CharHpMax
print "The Character's Current Hp is: ",self.CharHpCurrent
print "The Character's max Mp is: ",self.CharMpMax
print "The Character's current Mp is: ",self.CharMpCurrent
print "The Character's Strength is: ",self.CharStr
print "The Character's Defence is: ", self.CharDef
print "The Character's Magic Power is: ", self.CharMAtt
print "The Character's Magic Resistance is: ", self.CharMDef
fileChar = open('Character Data\ '+self.Name+'.txt','a')
fileChar.writelines(className+','+self.CharHpMax+','+self.CharHpCurrent+','+self.CharMpMax+','+self.CharMpCurrent+','+self.CharStr+','+self.CharDef+','+self.CharMAtt+','+self.CharMDef+','+str(self.Currentexp)+','+str(self.Requiredexp))
self.mainGame()
self.classChoose.destroy()
I'm trying to work in a second class, but it won't work. I want it to read a line, see if the first thing in the line matches the selected class (Warrior or Brute) and give stats accordingly, but it does both!
The stats are on the next line of the text file:
Warrior,250,250,20,20,25,30,10,5
Brute,300,300,0,0,30,20,5,2