Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So, first of all, follow a naming convention, for python code I recommend that you use the <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">pep8</a> as a convention.</p> <p>You have a problem with classes vs. instances in you code, first you need an instance of a class before you can use it:</p> <pre><code>enemy = random_enemy() # a better name would be RandomEnemy </code></pre> <p>In python all methods start with <code>self</code>, and you need to pass to the method the arguments that it needs to do its work, <code>weak</code> is a method, so it should be more like this:</p> <pre><code>def weak(self, player): # the method for weak ... weak attack ? # remember to change p to player, which is more meaningful ... </code></pre> <p>Now that you have your instance and it has a method <code>weak</code> which receives a <code>player</code> as argument, you can use it as follows:</p> <pre><code># you can't use random_enemy here as you tried because it is a class # you need a random_enemy instance, the enemy that I talked about earlier b = enemy.weak(player) # renamed p to player because it is more meaningful </code></pre> <p>For this all to work, you will need one more thing, <code>weak()</code> needs to returning something. Right now you are using what it returns, nothing! The code that you posted is <code>b = random_enemies.weak()</code>, because <code>weak()</code> does not have a <code>return</code> clause <code>b</code> will always be <code>None</code>.</p> <p>Some notes: Avoid one letter variables unless it is a long standing convention (like using <code>i</code> for loop counter), it is easier to understand what you are trying to do if you call it <code>player</code> instead of just <code>p</code>.</p> <p>Python has a really great <a href="http://docs.python.org/2/tutorial/" rel="nofollow">tutorial for all this stuff</a>.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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