1

Here is my code:

if mgc == 0 and event.type == MOUSEBUTTONDOWN and pygame.mouse.get_pos() >= (250, 15) and pygame.mouse.get_pos() <= (363, 51):
    ofnt_thing = input("What font would you like your score to be in? ")
    if ofnt_thing == "":
        file = open("fontdefault.txt", "r+")
        default = file.read()
        print("Set to default: " + default)
        ofnt_thing = default
        file.close()
    elif ofnt_thing == "set_default()":
        newfile = open("fontdefault.txt", "w+")
        newdef = input("New default font: ")
        newfile.write(newdef)
        ofnt_thing = newdef
        newfile.close()
    ofnt = pygame.font.SysFont(str(ofnt_thing), 50)
    stxt = ofnt.render(str(score), False, (255, 20, 255))
if mgc == 0 and event.type == MOUSEBUTTONDOWN and pygame.mouse.get_pos() >= (250, 65) and pygame.mouse.get_pos() <= (437, 100):
    if lag == True: lag = False
    else: lag = True

So, when I run this part of my program, it is supposed to ask for a change in font if the mouse's x-value is between 250 and 363 and the y-value between 15 and 51. This works just fine. However, for the lag toggle button, it asks for a font change when I click in the middle or to the left of the button. Why is this happening?

  • `pygame.mouse.get_pos() >= (250, 15)` What data type does `get_pos()` return? I'm not sure you can compare it this way. – John Gordon Mar 02 '19 at 21:41
  • How would I compare it? `get_pos()` returns a tuple in the form of (x, y). – Voldemort's Wrath Mar 02 '19 at 21:42
  • 1
    I believe that comparison does work as tuple comparison is done item by item. – GRAYgoose124 Mar 02 '19 at 21:43
  • That's what I figured because it worked with the font change. – Voldemort's Wrath Mar 02 '19 at 21:44
  • Assuming `get_pos()` returns an `(x, y)` tuple, the comparison `get_pos() > (250, 15)` will be true if the X position is larger than 250, and it won't bother checking the Y position at all. Is that what you intended? – John Gordon Mar 02 '19 at 21:47
  • Are you certain about this? If this is true, it certainly was NOT what I intended and I thank you greatly for your help. It appears that I may have to split it up into its x- and y-components. – Voldemort's Wrath Mar 02 '19 at 21:49
  • 1
    That's what @GRAYgoose124 meant by item-by-item comparison. If the first item is bigger, then it doesn't bother checking the rest. – John Gordon Mar 02 '19 at 21:50

0 Answers0