Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8313621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:33:02+00:00 2026-06-08T20:33:02+00:00

I recently downloaded Kivy as it’s given me the most comprehensible tutorials and documentation,

  • 0

I recently downloaded Kivy as it’s given me the most comprehensible tutorials and documentation, etc. I’ve tried pygame and cocos but never could get a foundation, and with Kivy it’s been easy.

So heres my problem, I’ve made a pong game, and I’m trying to make the game pause by stopping the pong ball, and then starting it again when it’s unpaused (by changing its velocity).

Here’s my code:

class PongGame(Widget):
   ...

    def _on_keyboard_down(self, keyboard, keycode, text, modifiers):
        if keycode[1] == 'escape':
        #Why doesnt it work without global?
        #If I don't use a global i get "tempBallVelocity referenced before assignment
            global tempBallVelocity
            tempBallVelocity = self.ball.velocity
            self.ball.velocity = 0,0


        if keycode[1] == '`':
            #Make the ball go again, thus exiting pause
            #This is where the error occurs if I don't use global
            self.ball.velocity = tempBallVelocity   

As you can see in the comments, If I don’t use global, I get referenced before assignment error. But it’s a local variable, I don’t understand why this is happening.

Anyone have any ideas? thanks?

Edit: Just to make sure everyone is clear in my intentions, I do NOT want to use a global, but it’s the only way it will work. I would prefer not to use globals.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:33:03+00:00Added an answer on June 8, 2026 at 8:33 pm

    If you fix the indentation error again you will see that:
    You can see that:

    1. the escape escape should work without the global, however tempBallVelocity will be considered as a local variable. If you want to modify a global variable you need to add the global declaration to tell python that tempBallVelocity is not local but global.

    2. In the second case, tempBallVelocity is not locally initialized if you do not enter the escape block and thus cannot be used as a local RValue. In this case python should look for the variable outside of the class. Is tempBallVelocity really a global variable ?

    remark: if the cases are exclusive you should use elif instead of if for the second case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I just recently downloaded the most recent snow leopard update. Then I tried
I have recently downloaded the most recent build of this awesome tool WSDL2OBJC from
I recently downloaded http://boost-log.sourceforge.net/libs/log/doc/html/index.html but I can't seem to find out how to build
I just recently downloaded the dom4j library, but for the life of me I
I have recently downloaded Windows Phone Toolkit ( November 2011, 7.1 SDK ) but
I'd recently downloaded a project on SMS sending, but when I tries to compile
i have recently downloaded ZBar SDK, and now wanted to scan barcode, but in
I recently downloaded the Android Support Package and have been using it trying to
I recently downloaded the checkstyle 5.5 distribution . It contains two JAR files, checkstyle-5.5.jar
I recently downloaded Visual Studio 2010b2, and wanted to re-evaluate some of my questions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.