Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
UnboundLocalError Problem
#1
So I am making my first game in python. It is a text RPG. Obviously I can't post the entire code on here, but I think this will be enough to hopefully get this solved.

So right now I am creating achievements. For example, I have one where defeating 10 enemies gives you an achievement titled "soldier". My problem is with this. I set my enemies defeated to 9 and then went into combat and defeated one more to see if the achievement would work. I got this error:
Error:
File "C:/Users/DESKTOP/.PyCharmCE2018.3/config/scratches/Text RPG.py", line 672, in earn_achievement if player.enemies_killed >= 10 and soldier_achievement == False: UnboundLocalError: local variable 'soldier_achievement' referenced before assignment
This is the code that it is referencing:

soldier_achievement = False
hunter_achievement = False
slayer_achievement = False
executioner_achievement = False
john_achievement = False
shopper_achievement = False
merchant_achievement = False
cheater_achievement = False
dedication_achievement = False
frich_achievement = False
frrich_achievement = False
fstich_achievement = False
explorer_achievement = False
def earn_achievement():
    if player.enemies_killed >= 10 and soldier_achievement == False:
        print("#######################")
        print("# Achievement Earned! #")
        print("#      'Soldier'      #")
        print("#######################")
        player.achievements.append('Soldier')
        soldier_achievement = True
        player.gold += 10
        prompt()
I've been looking at this for an hour and trying different things to get it to work, but nothing has changed. Anyone have any ideas? If you need more information I will gladly give some.
Reply


Messages In This Thread
UnboundLocalError Problem - by DrChicken24 - Mar-27-2019, 02:28 AM
RE: UnboundLocalError Problem - by ichabod801 - Mar-27-2019, 02:53 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How does UnboundLocalError work? deanhystad 3 1,682 Feb-25-2022, 01:21 AM
Last Post: bowlofred
  UnboundLocalError: local variable 'wmi' referenced before assignment ilknurg 2 1,914 Feb-10-2022, 07:36 PM
Last Post: deanhystad
  exec + subprocess = UnboundLocalError paul18fr 6 3,509 Feb-04-2021, 06:27 AM
Last Post: Gribouillis
  UnboundLocalError: local variable 'figure_perso' referenced before assignment mederic39 2 2,275 Jun-11-2020, 12:45 PM
Last Post: Yoriz
  UnBoundLocalError Seaninho 3 2,695 May-31-2020, 07:22 AM
Last Post: azajali43
  UnboundLocalError: local variable referenced before assignment svr 1 3,309 Dec-27-2019, 09:08 AM
Last Post: perfringo
  UnboundLocalError: local variable ' ' referenced before assignment d3fi 10 5,565 Sep-03-2019, 07:22 PM
Last Post: buran
  'Exception Has occured: UnBoundLocalError' caston 1 2,462 Jun-12-2019, 02:33 PM
Last Post: perfringo
  UnboundLocalError, how to fix it please? etrius 4 3,888 Jan-18-2018, 09:53 PM
Last Post: nilamo
  How to fix UnboundLocalError Tawnwen 5 5,368 Jan-07-2018, 05:38 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020