Don Beto
Don Beto

Reputation: 132

Boolean evaluation between two lists is not working

I have a doubt about this evaluation, "old", which is a list of tuples should be evaluating False when evaluating with bp_list which is the same list of tuples, but with an item less. Thank you so much in advance.

while True: # game loop
    if dead_flag == True:
        pygame.time.wait(2000)
        dead_flag = False    
    MAINSURF.fill(BLACK)

    thePill.drawPills(p_inventary)
    oldpoints = points
    p_inventary, points = thePill.eatenPill(pac._x, pac._y, p_inventary)

    bigPill(*bp_list)
    #### This is the problematic part
    old = bp_list
    print ">>>", old
    bp_list = eatBig(bp_list, pac._x, pac._y)
    print "---",bp_list
    if (old != bp_list):
        print "they're different"
        print "##", old_bp_list
        print "##", bp_list
        score += 50

    if oldpoints != points:
        score = (basep - points) * 10


    """else: 
        print "old_bp_list ", old_bp_list
        print "bp_list ", bp_list    """     
    if p_inventary == []:
        break

Upvotes: 0

Views: 68

Answers (1)

user2357112
user2357112

Reputation: 280887

old = bp_list

This line doesn't turn old into a copy of bp_list. After this line, old and bp_list both refer to the same object, and any modifications to bp_list will show up on old.

Upvotes: 1

Related Questions