TypeError: 'NoneType' object is not iterable, pygame












0















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










share|improve this question




















  • 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 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





    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
















0















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










share|improve this question




















  • 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 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





    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














0












0








0








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










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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 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





    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














  • 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 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





    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








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












1 Answer
1






active

oldest

votes


















1














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.






share|improve this answer























    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    1














    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.






    share|improve this answer




























      1














      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.






      share|improve this answer


























        1












        1








        1







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 23:22









        Tarik KrandaTarik Kranda

        111




        111
































            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Costa Masnaga

            Fotorealismo

            Sidney Franklin