0

Ok, so you might find this stupid and yes I am a beginner when it comes to programming but would it be possible to do something like that? My friend tried to execute it with some extra code to make it complete but it couldn't even start. I'm pretty sure I messed the list up so i appreciate tips and corrections :)

import time

character_list = [a,b,c,d] # creating list with characters
buttons_list = [pygame.K_a,pygame.K_b,pygame.K_c,pygame.K_d]#creating list with key-events
while True:

    millis = int(round(time.time()*1000))
    hours = int(round( millis / 3600000))
    # print a letter to the screen with character_list[hours]
    necessary_button  = buttons_list[hours]
    if event.type == pygame.KEYDOWN:
        if event.key == necessary_button:
            # do some awesome stuff

So here's the code I got from my friend:

    import pygame

    pygame.init()

    display_width = 1600
    display_height = 900

    white = (255,255,255)
    black = (0,0,0)
    red = (255,0,0)
    green = (0,155,0)

    game_display = pygame.display.set_mode((display_width,display_height))
    pygame.display.set_caption('AYYLMAO')

    smallfont = pygame.font.SysFont("comicsansms",25)

    def text_objects(text,color,size):
        if size == "small":
            textSurf = smallfont.render(text, True, color)
        return textSurf, textSurf.get_rect()



    def message_to_screen(msg, color, y_displace = 0,size = "small"):
        textSurf, textRect = text_objects(msg,color,size)
        textRect.center = (display_width/2), ( display_height/2)+y_displace
        game_display.blit(textSurf, textRect)

    def gameLoop():
        game_display.fill(white)
        character_list = ["a","b","c","d","e"]
        buttons_list = [pygame.K_a, pygame.K_b, pygame.K_c, pygame.K_d, pygame.K_e]

        message_to_screen(character_list[0], red)
        pygame.display.update()
        necessary_button = buttons_list[0]
        if event.type == pygame.KEYDOWN:
            if event.key == necessary_button:
                message_to_screen(GG, red)
            if event.key == pygame.K_ESCAPE:
                pygame.QUIT()


    gameLoop()

This prints the "a" to the screen at least but i get the error: "line 38, in gameLoop if event.type == pygame.KEYDOWN: NameError: global name 'event' is not defined." I hope this not just another stupid mistake by me :D

  • 1
    huh? What is the question? You already have the list with key events, what do you want/need? What have you donde that has/hasn't worked ? What is the expected result? – tglaria Jan 25 '16 at 20:34
  • 1
    I'm gonna update it tomorrow with the code my classmate wrote. Gotta go for today. Ah by the way the error he got before the program even started was "a is not defined" but there wasn't even an "a" used in there. – Yannick Dannies Jan 25 '16 at 20:43
  • 1
    `a` is variable name, use `"a"` if you need text/char. `character_list = ["w", "a", "s", "d"]` – furas Jan 25 '16 at 21:20
  • ah damn right thanks once again furas. I should've at least known that :/ – Yannick Dannies Jan 25 '16 at 21:32
  • 1
    btw: it should be `event.key` (not `event.type`) in `if event.type == necessary_button:` – furas Jan 25 '16 at 21:37

0 Answers0