TypeError: 'NoneType' object is not iterable, pygame
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
python pygame
add a comment |
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
python pygame
1
May be you should update your question withtext_objects
definition.
– Abdul Niyas P M
May 4 '18 at 1:12
I did, thank you.
– Whitepub
May 4 '18 at 1:13
2
Yourtext_objects
method returnsNone
, That is why you are gettingTypeError: 'NoneType' object is not iterable
.
– Abdul Niyas P M
May 4 '18 at 1:15
1
A function that doesn't have areturn
statement automatically returnsNone
. Whatever you wanted it to return instead, you have to tell Python that explicitly.
– abarnert
May 4 '18 at 1:15
add a comment |
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
python pygame
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
python pygame
python pygame
edited May 4 '18 at 1:15
DYZ
26.8k62049
26.8k62049
asked May 4 '18 at 1:08
WhitepubWhitepub
367
367
1
May be you should update your question withtext_objects
definition.
– Abdul Niyas P M
May 4 '18 at 1:12
I did, thank you.
– Whitepub
May 4 '18 at 1:13
2
Yourtext_objects
method returnsNone
, That is why you are gettingTypeError: 'NoneType' object is not iterable
.
– Abdul Niyas P M
May 4 '18 at 1:15
1
A function that doesn't have areturn
statement automatically returnsNone
. Whatever you wanted it to return instead, you have to tell Python that explicitly.
– abarnert
May 4 '18 at 1:15
add a comment |
1
May be you should update your question withtext_objects
definition.
– Abdul Niyas P M
May 4 '18 at 1:12
I did, thank you.
– Whitepub
May 4 '18 at 1:13
2
Yourtext_objects
method returnsNone
, That is why you are gettingTypeError: 'NoneType' object is not iterable
.
– Abdul Niyas P M
May 4 '18 at 1:15
1
A function that doesn't have areturn
statement automatically returnsNone
. Whatever you wanted it to return instead, you have to tell Python that explicitly.
– abarnert
May 4 '18 at 1:15
1
1
May be you should update your question with
text_objects
definition.– Abdul Niyas P M
May 4 '18 at 1:12
May be you should update your question with
text_objects
definition.– Abdul Niyas P M
May 4 '18 at 1:12
I did, thank you.
– Whitepub
May 4 '18 at 1:13
I did, thank you.
– Whitepub
May 4 '18 at 1:13
2
2
Your
text_objects
method returns None
, That is why you are getting TypeError: 'NoneType' object is not iterable
.– Abdul Niyas P M
May 4 '18 at 1:15
Your
text_objects
method returns None
, That is why you are getting TypeError: 'NoneType' object is not iterable
.– Abdul Niyas P M
May 4 '18 at 1:15
1
1
A function that doesn't have a
return
statement automatically returns None
. Whatever you wanted it to return instead, you have to tell Python that explicitly.– abarnert
May 4 '18 at 1:15
A function that doesn't have a
return
statement automatically returns None
. Whatever you wanted it to return instead, you have to tell Python that explicitly.– abarnert
May 4 '18 at 1:15
add a comment |
1 Answer
1
active
oldest
votes
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.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50165753%2ftypeerror-nonetype-object-is-not-iterable-pygame%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 23 '18 at 23:22
Tarik KrandaTarik Kranda
111
111
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50165753%2ftypeerror-nonetype-object-is-not-iterable-pygame%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
May be you should update your question with
text_objects
definition.– Abdul Niyas P M
May 4 '18 at 1:12
I did, thank you.
– Whitepub
May 4 '18 at 1:13
2
Your
text_objects
method returnsNone
, That is why you are gettingTypeError: 'NoneType' object is not iterable
.– Abdul Niyas P M
May 4 '18 at 1:15
1
A function that doesn't have a
return
statement automatically returnsNone
. Whatever you wanted it to return instead, you have to tell Python that explicitly.– abarnert
May 4 '18 at 1:15