Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get certain outputs out of a dict block
    primarykey
    data
    text
    <p>My RPG-related issues have transmogrified. I have a dict block of weapons, defined with (I believe) their value and damage. How do I generate a certain weapon as output, say, for a merchant to have for sale?</p> <p>Here's the weapon class:</p> <pre><code>class weapon(object): def __init__(name, loot_worth, damage): Character.__init__(self) self.damage = Damage def Damage(weapon): self.damage = Damage </code></pre> <p>Segment of dict block:</p> <pre><code>weapon_dict = {"None" : [0, 0], "Imaginary Sword" : [0, 0], "Twig" : [0, 1] } </code></pre> <p>The merchHasWeapon function block:</p> <pre><code>def merchHasWeapon(self): if self.merchstate == 'buy': return random.choice(weapon_dict.keys()) </code></pre> <p>And the merch function:</p> <pre><code>def merch(self): self.merchstate == 'buy' self.merchstim = randint (0, 10) self.merchammo = randint (0, 50) if randint(0, 1): temp_wpn = self.merchHasWeapon() temo_armr = self.merchHasArmor() print("Merch weapon: {} , Stats: {}".format(temp_wpn,weapon_dict[temp_wpn])) print("Merch armor: {} , Stats: {}".format(temo_armr,armor_dict[temo_armr])) print "%s goes to the Merchants' Clearing. For help with merchants, type mh." % self.name print "Merchant's items:\n~Potions:%d\n~Arrows:%d\n" % (self.merchstim, self.merchammo) </code></pre> <p>The error message that prints if the "def merchHasWeapon" block comes before the "def merch" block is "zero length field name in format." If it comes after, it says "global name merch isn't defined." Could someone help me remedy this error? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload