omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    2
    3
    1569
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Pythonistapro777
      Pythonistapro777 last edited by

      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 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())
      </code></pre>

      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by

        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)
        
        1 Reply Last reply Reply Quote 0
        • Pythonistapro777
          Pythonistapro777 last edited by

          Thanks a bunch!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors