Python Forum
Unable to unpack at line 184
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to unpack at line 184
#1
Good day to all. Im new to the forums and want to excel in Python.

This a simple code for an RPG game with the above error in line 184. Would like to know where I have gone wrong to avoid such mistakes in the future.

Game class - https://pastebin.com/8TWH5dBT
Magic class - https://pastebin.com/Am4Ff2Zh
Inventory class - https://pastebin.com/6bVGSsHD

Main file - https://pastebin.com/StPDRJ20
Reply
#2
It's not a good idea to use pastebin.
Reply
#3
    def choose_enemy_spell(self):
        magic_choice = random.randrange(0, len(self.magic))
        spell = self.magic[magic_choice]
        magic_dmg = spell.generate_damage()

        pct = self.hp / self.maxhp * 100

        if self.mp < spell.cost or spell.type == "white" and pct > 50:
            self.choose_enemy_spell()
        else:
            return spell, magic_dmg
In one case you return nothing, in the other case you return (spell, magic_dmg). It is the first case that will give you the error.
Nitil likes this post
Reply
#4
Somewhere in your code there must be line that looks something like

spell, dmg = choose_enemy_spell()
Python is telling us that it is "unable to unpack". Consider what spell and dmg variables would be in the case where nothing is returned.

/regards
Nitil likes this post
Reply
#5
Thank you all for the support.
I made the said changes and the code is working fine.

I'll make sure to ask the questions in the right format from the next time. Please pardon me
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python code unable to show Bokeh line chart kirito85 2 2,579 Feb-06-2019, 07:52 AM
Last Post: kirito85

Forum Jump:

User Panel Messages

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