Can't find the mistake. who will help?

error:
Traceback (most recent call last):
 File "C:/DinoGame/DinoGame.py", line 92, in <module>
run_game()
 File "C:/DinoGame/DinoGame.py", line 54, in run_game
draw_array(cactus_arr)
 File "C:/DinoGame/DinoGame.py", line 86, in draw_array
 check = cactus.move()
 File "C:/DinoGame/DinoGame.py", line 29, in move
 if self.x >= -self.width:
TypeError: '>=' not supported between instances of 'NoneType' and 'int'


code:
import pygame
import random
pygame.init()
display_width = 800
display_height = 600
display = pygame.display.set_mode((display_width, display_height))
pygame.display.set_caption('DinoRun')
icon = pygame.image.load('Sprite-0001.png')
pygame.display.set_icon(icon)
usr_width = 60
usr_height = 100
usr_x =display_width//3
usr_y =display_height-100-100
clock = pygame.time.Clock()
make_jump = False
jump_counter = 30
cactus_width =20
cactus_height =70
cactus_x=800-50
cactus_y=600-100-70
class Cactus:
 def __init__(self,x,y,width,height,speed):
 self.x = x
 self.y = y
 self.width = width
 self.height = height
 self.speed = speed
 def move(self):
 if self.x >= -self.width:
 pygame.draw.rect(display, (5, 149, 0), (self.x self.y self.width, self.height))
 self.x -= self.speed
 return True
else:
 self.x = display_width + 100 + random.randrange(-80,60)
 return False
 def return_self(self,radius):
 self.x = radius
def run_game():
 global make_jump
 game = True
 cactus_arr =[]
create_cactus_arr(cactus_arr)
 while game:
 for event in pygame.event.get():
 if event.type == pygame.QUIT:
pygame.quit()
quit()
 key = pygame.key.get_pressed()
 if key[pygame.K_SPACE]:
 make_jump = True
 if make_jump:
jump()
display.fill((4,192,232))
draw_array(cactus_arr)
pygame.draw.rect(display,(232,44,4),(usr_x,usr_y,usr_width,usr_height))
pygame.display.update()
clock.tick(80)
def jump():
 global usr_y, make_jump, jump_counter
 if jump_counter >= -30:
 usr_y -= jump_counter/2.5
 jump_counter -=1
else:
 jump_counter = 30
 make_jump = False
def create_cactus_arr(array):
array.append(Cactus(display_width+20,display_height-170,20,70,4))
array.append(Cactus(display_width+300,display_height-150,30,50,4))
array.append(Cactus(display_width+600,display_height-180,25,80,4))
def find_radius(array):
 maximum = max(array[0].x, array[1].x, array[2].x)
 if maximum < display_width:
 radius = display_width
 if the radius of maximum < 50:
 radius += 150
else:
 radius = maximum
 choise = random.randrange(0,5)
 if choise == 0:
 radius += random.randrange(10,15)
else:
 radius += random.randrange(200,350)
 return radius
def draw_array(array):
 for cactus in the array:
 check = cactus.move()
 if not check:
 radius = find_radius(array)
cactus.return_self(radius)


run_game()
April 16th 20 at 10:46
2 answers
April 16th 20 at 10:48
Solution
Well, look. Message
self.x >= -self.width:
TypeError: '>=' not supported between instances of 'NoneType' and 'int'

which indicates that at the time of the error self.x = None
See initially, x is filled. So in the process he at some point is set to None.
This problem is seen only in return_selfwhere it is set to a passed radius
self.x = radius
which in turn is obtained from the function find_radius.
A cursory look at this feature is striking that the only return it because the padding is inside of the block if. Ie if the condition fails, the function just returns None, causing the error.
So the problem should be sought there. As the planned logic of the game I don't know, I suppose that it is enough just to correct the line return radius (remove extra space), it is logical to return a result, regardless of the conditions.
April 16th 20 at 10:50
Re-read carefully the error itself, check the string to which it points.
Yes, I have already read. I don't know how to fix it - Nathan.Hirthe commented on April 16th 20 at 10:53

Find more questions by tags pygamePython