Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
[SOLVED!] Help with 'Nonetype' error
-
I'm making a gravity guy game. Will be completed tomorrow, I hope. :)
Please help with the error that pops up when the code is run.
Thanks in advance!
Here's the code:
<pre><code>
from scene import *
from random import randomclass MyScene (Scene):
def setup(self):
self.x=70
self.y=224
self.g = 0.5 #gravity
self.acel = 0
self.grav = Truedef draw(self): background(0, 0.5, 1.0) self.player=rect(self.x,self.y,32,32) fill(0,0,0) self.roof=rect(self.x-70,self.y+75,700,32) self.floor=rect(self.x-70,self.y-75,700,32) self.player.background=Color(1,1,1) if not self.grav: self.acel += 1 def touch_began(self, touch): self.grav = not self.grav def touch_moved(self, touch): pass def touch_ended(self, touch): pass
run(MyScene())
</code></pre> -
You define
self.player
as the return value of therect(...)
call, butrect
doesn't return anything, it just draws a rectangle... soself.player
isNone
afterwards. To set the fill color of the rectangle (which seems to be your intention), call thefill
function before drawing the rectangle, something like this:fill(1, 1, 1) # the rectangle will be white now: rect(self.x, self.y, 32, 32)
-
Thanks a bunch!