Note that there are some explanatory texts on larger screens.

plurals
  1. PO"Tuple" Object Does Not Support Item Assignment, Test-Based RPG
    text
    copied!<p>As a separate part of the same RPG, I'm having issues attacking enemies. The function do_damage takes the name/value(health) from the enemy_dict list and computes damage done. </p> <pre><code>def do_damage(self, enemy): damage = min( max(randint(0, self.health) - randint(0, self.enemy[1]), 0), self.enemy[1]) self.enemy[1] = self.enemy[1] - damage if damage == 0: print "The %s evades %s's attack." % (self.enemy[0], self.name) else: print "%s hurts the %s! -%dhp" % (self.name, self.enemy[0], damage) return enemy[1] &lt;= 0 </code></pre> <p>self.enemy is assigned like so:</p> <pre><code>self.enemy = random.choice(enemy_dict) </code></pre> <p>as a part of the explore function, which, when called, provides a chance to encounter an enemy.</p> <p>The attack function, when called by the player, calls the do_damage function.</p> <pre><code>def attack(self): if self.state != 'fight': print"%s swings wildly at nothing." % self.name else: if self.do_damage(self.enemy[1]): print "%s slaughters %s!" % (self.name, self.enemy[0]) self.enemy = None self.state = 'normal' eloot = randint(0,25) self.loot = self.loot + eloot qxp = randint(0,30) self.xp = qxp + self.xp print "You find %d gold on the corpse." %(eloot) stimp = randint(0,4) if stimp == 0: self.stim = self.stim + 1 print "You find a potion!" else: self.enemy_attacks() def enemy_attacks(self): if self.enemy[0].do_damage(self): print "%s was disemboweled by %s!" % (self.name, self.enemy[0]) </code></pre> <p>The attack function is a part of the Player class while do_damage is part of the Character class, which is called in the Player class.</p> <p>For reference, here's the enemy_dict list:</p> <pre><code>enemy_dict = [ ("sprite", 5), ("thief", 10) ] </code></pre> <p>How do I allow the player to attack an enemy, with what I've got?</p>
 

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