Why is this start_pos invalid?

Question:

Why does this code not work?

def grid(vl):
    vl_var = screen.get_width() / vl
    i = 1
    while True:
        if i == vl:
            i = 1
            break
        else:
            pygame.draw.line(screen, (94, 94, 94), vl_var * i, vl_var * i * screen.get_width())
            i += 1

When executing this program, i get the following error

TypeError: invalid start_pos argument

I have no idea why this would be invalid…

Asked By: Mika Zirklewski

||

Answers:

To draw a line you need to specify the start and end position. A position is a tuple with a x and y coordinate. pygame.draw.line draws a line from a start and end position specified in the third and fourth parameters. e.g.:

def grid(vl, hl):
    width, height = screen.get_size()
    vl_var = width // vl
    hl_var = height // hl
    # vertical lines
    for i in range(vl+1):
        pygame.draw.line(screen, (94, 94, 94), (vl_var*i, 0), (vl_var*i, height))
    # horiontal lines
    for i in range(hl+1):
        pygame.draw.line(screen, (94, 94, 94), (0, hl_var*i), (width, hl_var*i))
Answered By: Rabbid76
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.