I'm trying to create a virtual restaurant menu, and clicking a button assigns a number that corresponds to the index of an appetizer and entree list I created earlier. I'm not sure how to keep the value of app_ix and entree_ix because I can't call the meal() function without those values and pressing escape will erase those values and cause a local variable error where the entree_ix and app_ix don't have a value, yet they are being called as arguments for the meal() function.
def screen(app, ent):
mx, my = pygame.mouse.get_pos()
if app == 1:
running = True
while running:
window.fill(WHITE)
window.blit(menu, (0, 0))
app_box_one = pygame.Rect(WIDTH/3 - 100, HEIGHT/5, 400, 100)
pygame.draw.rect(window, NUTMEG, app_box_one)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
if event.type == pygame.MOUSEBUTTONDOWN:
if app_box_one.collidepoint(mx, my):
running = False
app_ix = 0
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
running = False
pygame.display.update()
main_clock.tick(60)
if ent == 1:
running = True
while running:
window.fill(WHITE)
window.blit(menu, (0, 0))
option_box_one = pygame.Rect(WIDTH/3 - 100, HEIGHT/5, 400, 100)
pygame.draw.rect(window, NUTMEG, option_box_one)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
if event.type == pygame.MOUSEBUTTONDOWN:
if option_box_one.collidepoint(mx, my):
running = False
entree_ix = 0
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
running = False
pygame.display.update()
main_clock.tick(60)
def meal(app_index, entree_index):
window.fill(WHITE)
window.blit(menu, (0, 0))
meal_font = pygame.font.SysFont('corbel', 50, True)
meal_message = app_list[app_index] + entree_list[entree_index]
final_meal_message = meal_font.render(meal_message, True, BLACK)
window.blit(final_meal_message, (WIDTH/2 - 50, HEIGHT/2 - 50))
pygame.display.update
main()