Reputation: 67
def text_objects(text, color, size="small"):
smallfont = pygame.font.SysFont("comicsansms", 26)
if size == "small":
textSurface = smallfont.render(text, True, color)
def screen_message(msg, color, y_displace=0):
textSurf, textRect = text_objects(msg, color)
textRect.center = (int(display_width / 2), int(display_height / 2) + y_displace)
gameDisplay.blit(textSurf, textRect)
This is the part of codes that I have an error
Error says,
line 74, in game_intro screen_message("Welcome to Titans!", white, -100)
which is screen_message("Welcome to Titans!", white, -100)
line 52, in screen_message textSurf, textRect = text_objects(msg, color)
TypeError: 'NoneType' object is not iterable
I do not understand the error why it is talking about NoneType
Upvotes: 0
Views: 291
Reputation: 41
Your text_objects function has no return statement inside, whereas you assign its return value into textSurf, textRect in the first line of screen_message function.
You should ensure that your text_objects returns that value pairs in any case. Sometimes people places some if statements for checks before return statements but forget else situations etc. Functions calls which is used as right hand value of an assignment with missing return statements inside can generate this TypeError("'NoneType' object is not iterable",) error.
Upvotes: 1