Reputation: 25
I'm relatively new when it comes to python, and do know how to convert strings to integers. However, for some reason I'm unable to when drawing lines from pygame. Before converting the code to integer, it said I had a deprecation warning and required integers instead of the floats I had. I did what it told me, but now I get an error saying int() can't convert non-string with explicit base.
Before conversion:
def draw_board(board):
pygame.draw.line(screen,WHITE, (WIDTH/3,0),(WIDTH/3,HEIGHT),5)
pygame.draw.line(screen,WHITE,(WIDTH/1.5,0),(WIDTH/1.5,HEIGHT),5)
pygame.draw.line(screen,WHITE,(0,HEIGHT/1.5),(WIDTH,HEIGHT/1.5),5)
pygame.draw.line(screen,WHITE,(0,HEIGHT/3),(WIDTH,HEIGHT/3),5)
After conversion:
def draw_board(board):
pygame.draw.line(screen,WHITE, (int (WIDTH/3,0), int (WIDTH/3,HEIGHT)),5)
pygame.draw.line(screen,WHITE,(int (WIDTH/1.5,0), int (WIDTH/1.5,HEIGHT)),5)
pygame.draw.line(screen,WHITE,(int (0,HEIGHT/1.5), int (WIDTH,HEIGHT/1.5)),5)
pygame.draw.line(screen,WHITE,(int (0,HEIGHT/3),int (WIDTH,HEIGHT/3)),5)
Upvotes: 1
Views: 75
Reputation: 596
pygame.draw.line(screen,WHITE, (int (WIDTH/3,0), int (WIDTH/3,HEIGHT)),5)
There are two problems here.
(int (WIDTH/3,0), int (WIDTH/3,HEIGHT))
This combines two of your arguments into a tuple - which I'm guessing isn't what you want.
int (WIDTH/3,0)
This passes two arguments to the int function - which isn't what you want either.
For division between two integers, you may/should have the option of using the "floor division" operator e.g.
WIDTH // 3
Otherwise, you'll want something more like:
pygame.draw.line(screen,WHITE,(0, int(HEIGHT/1.5)), (WIDTH, int(HEIGHT/1.5)),5)
Upvotes: 4