Forum Archive

[SOLVED!] Help with 'Nonetype' error

Pythonistapro777

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:


from scene import *
from random import random

class MyScene (Scene):
    def setup(self):
        self.x=70
        self.y=224
        self.g = 0.5 #gravity
        self.acel = 0
        self.grav = True


    def 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())
omz

You define self.player as the return value of the rect(...) call, but rect doesn't return anything, it just draws a rectangle... so self.player is None afterwards. To set the fill color of the rectangle (which seems to be your intention), call the fill 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)
Pythonistapro777

Thanks a bunch!