python - "Invalid destination position for blit" in pygame when loading configuration from file -


i trying unsuccessfully load room file during runtime. confuses me line of code:

objglobal.instances.append(oplayer.oplayer(x, y))

successfully creates object when executed in main function, when put not when in file loading function:

file "e:\fun stuff\python stuff\python projects\simpleengine\main.py", line 56, in main objglobal.drawobjects(displaysurface) file "e:\fun stuff\python stuff\python projects\simpleengine\global.py", line 57, in drawobjects surface.blit(self.instances[i].sprite, (self.instances[i].x, self.instances[i].y)) typeerror: invalid destination position blit

that error occurs later on when try , call 1 of objects' variables or functions, of course. here function loading room:

def loadroom(objglobal, fname):      # list of stuff     openfile = open(fname, "r")     data = openfile.read().split(",")     openfile.close()      # loop through list assign said stuff     in range(len(data) / 3):          # create object @ position         x = data[i * 3 + 1]         y = data[i * 3 + 2]          # temporary object string         tempobject = data[i * 3]          # create object         if (tempobject == "oplayer"):             objglobal.instances.append(oplayer.oplayer(x, y))         elif (tempobject == "wall"):             objglobal.instances.append(commonobjects.wall(x, y))         else: # error found             print ("error: no object name '%s'" % (tempobject)) 

my file in correct format. note when call in main replace x , y 32, 32.

when reading in data file, in string format default. should convert integer format before constructing object it:

    x = int(data[i * 3 + 1])     y = int(data[i * 3 + 2]) 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -