Nicolas
Nicolas

Reputation: 19

If statement not calling function

For some reason my if statement won't do what it is meant to do. I am not sure as to why as i'm sure that I have formatted it correctly.

def attack():
    os.system('clear')
    pAttack=random.randint(playerIG.attack/2, playerIG.attack)
    eAttack=random.randint(enemy.attack/2, enemy.attack)
    if pAttack==playerIG.attack/2:
        print "You miss!"
    else:
        enemy.health-=pAttack
        print "You deal %s damage" % pAttack
    option=raw_input("")
    if enemy.health<=0:
        win()
    os.system('clear')
    if eAttack==enemy.attack/2:
        print "The enemy missed!"
    else:
        playerIG.health-=eAttack
        print "The enemy deals %s damage" % eAttack
    option=raw_input("")
    if playerIG.health<=0:
        die()
    else:
        fight()

The part we are looking at is:

if enemy.health<=0:
        win()

I'm not sure why but it won't call win() even when the enemy health is below zero.

Win function:

def win():
    print "You have successfully killed the %s!" % enemy.name
    print "You have gained %s gold!" % enemy.goldgain

Any solution will be helpful, thanks!

Upvotes: 0

Views: 52

Answers (1)

Fabricator
Fabricator

Reputation: 12772

You called os.system('clear') immediately after win(), so you won't see the win message.

Upvotes: 3

Related Questions