python - How do I use values from a tuple which is in a list of tuples as arguments for a function? -
i'm trying construct simple tilemap thingy, part of larger project, , 1 of solutions came out use function so:
def tile((value, x, y)): if value == 1: pygame.draw.rect(screen, (0, 0, 0) (x, y, 64, 64), 0)
the idea being set level out list of tuples contain value denotes tile drawn there, , coordinates of tile.
this, of course, doesn't work since can't use tuple argument.
my solution instead values out of tuple in list:
def tile(value, x, y): if value == 1: pygame.draw.rect(screen, (0, 0, 0) (x, y, 64, 64), 0) level = [(1, 0, 0), (rest of list)] tile(level[0[0]], level[0[1]], level[0[2]])
which didn't work, , gave me
traceback (most recent call last): tile(level[0[0]], level[0[1]], level[0[2]]) typeerror: 'int' object has no attribute '__getitem__'
does have workaround this? way can feed tuple function series of arguments? or using idiosyncratic method won't ever work ever? i'm guessing due blinding incompetence, although told otherwise.
python 2.7, pygame 1.9
you have answer best way handle task, specific problem way you're doing need level[0][0]
etc., not level[0[0]]
.
Comments
Post a Comment