b2 = raw_input("Select your action:")
    if b2 == "Attack":
        mgeHP = 2500
        print "You have decided to attack the mage."
        while True:
            dmg = random.randrange(1, 125, 1)
            mgeHPN = mgeHP-dmg
            print "You did" , dmg , "damge to the mage, giving it" , mgeHPN , "left"
            mgeHP = mgeHPN
            raw_input("Press ENTER")
            if mgeHP < 0:
                break

"File TrecherousMud.py",line166,in <module>
if b2 == "Attack":
NameError: name 'b2' is not defined.

If you need the entire code;

import random
print ">>If you don't type one of the choices exactly right, you'll need to restart<<"
print "Welcome, to this text adventure!"
name = raw_input("Please enter your name:")
print "So your name is " + name + "?"
raw_input("Press ENTER")
userHP = 100
print "Which dungeon do you wish to go to?"
print "Hope"
print "Grassy"
dungeon1 = raw_input("Which dungeon:")
if dungeon1 == "Grassy":
     print "So, you have chosen the Grassy Dungeon..."
     raw_input("Press ENTER")
     print "After exploring the caves, for 15 minutes, you run into a giant rat."
     raw_input("Press ENTER")
     print "Attack"
     print "Run"
     battle = raw_input("Select your action:")
     
     if battle == "Attack":
        ratHP = 100
        print "You have decided to attack the giant rat."
        while True:
            dmg = random.randrange(1, 10, 1)

            
            ratHPN = ratHP-dmg
            print "You did" , dmg , "damge to the rat, giving it" , ratHPN , "left"
            ratHP = ratHPN
            raw_input("Press ENTER")
            if ratHP < 0:
                break
            
        print "Congratulations, you killed the rat!"
        raw_input("Press ENTER")
     if battle == "Run":
            dmg2P = random.randrange(1, 10, 1)
            userHPN = userHP-dmg2P
            print "You decided to run away, you lost" ,dmg2P, "life, leaving you with", userHPN
            userhHP = userHPN
     print "Beach"
     print "Mountains"
     dungeon2 = raw_input("Which area:")
     if dungeon2 == "Beach":
         print "You have chosen to go to the beach..."
         raw_input("Press ENTER")
         print "After exploring the beach, for a hour, you run into a serpent."
         raw_input("Press ENTER")
         print "Attack"
         print "Run"
         battle = raw_input("Select your action:")
     if battle == "Attack":
        serpentHP = 500
        print "You have decided to attack the Serpent."
        while True:
            dmg = random.randrange(1, 25, 1)
            serpentHPN = serpentHP-dmg
            print "You did" , dmg , "damge to the Serpent, giving it" , serpentHPN , "left"
            serpentHP = serpentHPN
            raw_input("Press ENTER")
            if serpentHP < 0:
                break
            
        print "Congratulations, you killed the Serpent!"
        raw_input("Press ENTER")

     if battle == "Run":
            dmg2P = random.randrange(1, 20, 1)
            userHPN = userHP-dmg2P
            print "You decided to run away, you lost" ,dmg2P, "life, leaving you with", userHPN
            userhHP = userHPN
     if dungeon2 == "Mountains":
         print "You have chose to hike in the mountains..."
         raw_input("Press ENTER")
         print "At the peak, you fight a griffin."
         raw_input("Press ENTER")
         print "Attack"
         print "Run"
         battle2 = raw_input("Select your action:")
     if battle2 == "Attack":
        griffinHP = 1000
        print "You have decided to attack the griffin."
        while True:
            dmg = random.randrange(1, 50, 1)
            griffinHPN = griffinHP-dmg
            print "You did" , dmg , "damge to the griffin, giving it" , griffinHPN , "left"
            griffinHP = griffinHPN
            raw_input("Press ENTER")
            if griffinHP < 0:
                break
            
        print "Congratulations, you killed the griffin!"
        raw_input("Press ENTER")

     if battle2 == "Run":
            dmg2P = random.randrange(1, 50, 1)
            userHPN = userHP-dmg2P
            print "You decided to run away, you lost" ,dmg2P, "life, leaving you with", userHPN
            userhHP = userHPN


if dungeon1 == "Hope":
    print "So, you have chosen the Hope Dungeon..."
    raw_input("Press ENTER")
    print "Oh no! It's a trap, and you run into a bear"
    
    print "Attack"
    battle = raw_input("Select your action:")
     
    if battle == "Attack":
        bearHP = 250
        print "You have decided to attack the bear."
        bearHP = 250
    while True:
        dmg = random.randrange(1, 10, 1)
        bearHPN = bearHP - dmg
        print "You did" , dmg , "damge to the bear, giving it" , bearHPN , "left"
        bearHP = bearHPN
        raw_input("Press ENTER")
        if bearHP < 0:
            break
    
    print "Congratulations, you killed the bear!"
    raw_input("Press ENTER")

    print "Valley"
    print "Volcanic Valley"
    dungeon2 = raw_input("Which area:")
    if dungeon2 == "Valley":
         print "You decide to explore the valley."
         raw_input("Press ENTER")
         print "After searching for days, you find a dragon."
         raw_input("Press ENTER")
         print "Attack"
         print "Run"
         battle = raw_input("Select your action:")
    if battle == "Attack":
        dragHP = 5000
        print "You have decided to attack the dragon."
        while True:
            dmg = random.randrange(1, 250, 1)
            dragHPN = dragHP-dmg
            print "You did" , dmg , "damge to the dragon, giving it" , dragHPN , "left"
            dragHP = dragHPN
            raw_input("Press ENTER")
            if dragHP < 0:
                break
            
        print "Congratulations, you killed the dragon!"
        raw_input("Press ENTER")

    if battle == "Run":
            dmg2P = random.randrange(1, 40, 1)
            userHPN = userHP-dmg2P
            print "You decided to run away, you lost" ,dmg2P, "life, leaving you with", userHPN
            userhHP = userHPN
    if dungeon2 == "Volcanic Valley":
         print "You chose to venture into the Volcanic Valley."
         raw_input("Press ENTER")
         print "At the edge of a crater you find a fire mage"
         raw_input("Press ENTER")
         print "Attack"
         print "Run"
         b2 = raw_input("Select your action:")
    if b2 == "Attack":
        mgeHP = 2500
        print "You have decided to attack the mage."
        while True:
            dmg = random.randrange(1, 125, 1)
            mgeHPN = mgeHP-dmg
            print "You did" , dmg , "damge to the mage, giving it" , mgeHPN , "left"
            mgeHP = mgeHPN
            raw_input("Press ENTER")
            if mgeHP < 0:
                break
            
        print "Congratulations, you killed the mage!"
        raw_input("Press ENTER")

    if b2 == "Run":
            dmg2P = random.randrange(1, 125, 1)
            userHPN = userHP-dmg2P
            print "You decided to run away, you lost" ,dmg2P, "life, leaving you with", userHPN
            userhHP = userHPN
print "Thanks for playing"
raw_input("Press ENTER")

Your "b2" is initialized within an "if" block which may not be executed
during runtime. So one way is to initialize "b2" outside the "if" block
depending on what you want.

if dungeon2 == "Volcanic Valley":         
   ...    
   b2 = raw_input("Select your action:")   # this line may not be executed. 

if b2 == "Attack":
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.