I've been fixing problems with my code over the last few days, as I've been trying to add a start screen into my pygame code, I've sorted many errors but i couldn't figure out what was wrong with this one.
I'm using a variable name of inactive in the code to call it for a colour that's used for the 'buttons'on the screen.
this is the full error message
Traceback (most recent call last):
File "D:\Computing Homework\Programming Projects\pong development.py", line 8, in <module>
gameDisplay = pygame.display.set_mode([display_width,display_height,inactive,active])
NameError: name 'inactive' is not defined
I have tried to define inactive in different places throughout the code but to no advancement, I defined it at the top of the code, and i stopped getting the error message, but it also meant that when i ran the code nothing appeared not even the window for the start up screen showed up and 0 errors where thrown up.
Below is the code using the inactive:
def button(msg,x,y,width,height,active,inactive,action=None):
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
if ((x+width > mouse[0]) > x and (y+height > mouse [1] > y)):
pygame.draw.rect(gameDisplay, active,[x,y,width,height])
if click[0] == 1 and action != None:
if action == "play 1":
game_loop_one()
elif action == "play 2":
game_loop_two()
if x+width > mouse[0] > x and y+height > mouse[1] > y:
pygame.draw.rect(gameDisplay, active,(x,y,width,height))
else:
pygame.draw.rect(gameDisplay, inactive,(x,y,width,height))
smallText = pygame.font.Font("freesansbold.ttf",20) #defining the small text to be used on the buttons.
textSurface, textRect = text_objects(msg, smallText)
textRect.center = ( (x+(width/2)), (y+hight/2))
gameDisplay.blit(textSurface, textRect)
And here are the functions that are at the top of the program incase they are needed for fixing the problem :
display_width = 640
display_height = 480
gameDisplay = pygame.display.set_mode([display_width,display_height,inactive,active])
pygame.display.set_caption('Ethong')
fps = 60
pygame.font.init()
font = pygame.font.Font('freesansbold.ttf',115)
clock = pygame.time.Clock()
pygame.display.set_caption('ethong')
green = (0,200,0)#base colours.
white = (255,255,255)#base colours.
black = (0,0,0)#base colours.
red = (255,0,0)#base colours.
blue = (0,0,255)#base colours.
bright_green =(0,255,0)#defining colours this will be used to make the button 'glows' when hoovered over.
I expected the start screen to run and then display a start screen with the name of the game and two buttons, the buttons would be green, and then when hovered over, they would become bright green.
Instead I am stuck on an error to do with the inactive not being defined.