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 6834049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:03:47+00:00 2026-05-26T23:03:47+00:00

I have searched through similar questions on here, and cannot find an exact answer.

  • 0

I have searched through similar questions on here, and cannot find an exact answer. I keep getting a “…referenced before assignment” error.

I am trying to put two graphics objects returned from one function into two variables in another function.

I had basically the exact same piece of code in an earlier version, and it worked just fine.

I have the piece of code:

if moveE:
    moved_ctr, nT = MoveCharacter(ctr, spaceSize, borderSet, "east")
if moveW:
    moved_ctr, nT = MoveCharacter(ctr, spaceSize, borderSet, "west")
moved_ctr.draw(board)

This is what MoveCharacter() looks like:

def MoveCharacter(character, spSz, bdSet, direction):
    x1 = character.getCenter().getX()
    x2 = bdSet
    y1 = character.getCenter().getY()
    y2 = bdSet
    notifyText = Text(Point(100, 100), "")

    character.undraw()

    distance = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)

    if direction == "east":
            if distance < spSz:
                    character.move(spSz, 0)
            else:
                    notifyText.setText("You cannot move right from where you currently are.")
    if direction == "west":
            if distance > spSz:
                    character.move(-1 * spSz, 0)
            else:
                    notifyText.setText("You cannot move left from where you currently are.")

    return character, notifyText

And I keep getting the error:

Traceback (most recent call last):
  File "<pyshell#25>", line 1, in <module>
    Grid()
  File "<pyshell#24>", line 70, in Grid
    moved_ctr.draw(board)
UnboundLocalError: local variable 'moved_ctr' referenced before assignment
  • 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-05-26T23:03:48+00:00Added an answer on May 26, 2026 at 11:03 pm

    What happens before if moveE:?

    Most likely, moveE and moveW are falsey.

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

Sidebar

Related Questions

I have searched through the forum for my answer, But all the calendar questions
I have searched through many times but have not seen this before. Probably really
I have a problem which I cant seem to find answer to through searches
I have searched through stackoverflow and has found similar question. As I am still
Ok, I know similar questions have been asked, but my groveling through Google searches
I have searched through all the similar posts and google and have not quite
I have searched through the other questions and none of them seem to apply
I have searched through internet & found that there are no any direct method
I have searched through the net and still have no clue how to do
Im trying to translate an object without using glTranslate(). I have searched through web

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.