Hi there, I'm very new to programming, and I have this assignment where I'm supposed to create a 2D game in python. The character in the game is Homer Simpson, and I'm trying to get him to move within the maze thats already been created for me. I believe I have all the functions that are required to make him move, but when I try to call the functions in main I get this error:
ValueError: unpack tuple of wrong size
I somewhat understand that the sides of the line that I'm calling the functions on are uneven, but I don't know how to fix this? I'm sorry about the poor lingo.
Heres what I have so far for the functions:

# Definition for function destinationHomer ()
def destinationHomer (direction):
	print "  8  "
	print "4 5 6"
	print "  2  "
	direction = input ("Using the number compass above, enter the number coressponding to the direction in which you want Homer to move, (enter 5 to not move, or 0 to quit the game):")
	return direction

# Defintion for function moveHomer ()

def moveHomer (direction, aMaze, newRow, newColumn, currentRow, currentColumn):
	if (direction == 8) and (aMaze[currentRow - 1][currentColumn] != "#"):
        	                newRow = currentRow - 1
        	                newColumn = currentColumn
	elif (direction == 4) and (aMaze[currentRow][currentColumn - 1] != "#"):
        	                newRow = currentRow
        	                newColumn = currentColumn - 1
	elif (direction == 6) and (aMaze[newRow][newColumn + 1] != "#"):
		newRow = currentRow
		newColumn = currentColumn + 1
	elif (direction == 2) and (aMaze[newRow][newColumn] != "#"):  
		newRow = currentRow + 1
		newColumn = currentColumn
	elif (direction == 5):
	 	newRow = currentRow
		newColumn = currentColumn
	elif (direction == 0):
		newRow = currentRow
		newColumn = currentColumn
		gamestatus = GIVEN_UP
		print "Given up"
		newRow = currentRow
		newColumn = currentColumn
		print "D OHH! Invalid move, please re-enter the direction:"
	return newRow, newColumn

#Definition for function movingHomer ()

def movingHomer (aMaze, currentRow, newRow, currentColumn, newColumn):

	aMaze[currentRow][currentColumn] = " "
	aMaze[newRow][newColumn] = "H"
	currentColumn = newRow
	currentRow = newColumn
	return currentRow, newRow, currentColumn, newColumn

# and here is where I call them in main:

display (aMaze, articTime, currentRow, gameStatus) 

direction = destinationHomer (direction)

(newRow, newColumn, currentRow, currentColumn) = moveHomer (direction, aMaze, newRow, newColumn, currentRow, currentColumn) [B]#this is the row where the error occurs[/B]

movingHomer (aMaze, newRow, newColumn, currentRow, currentColumn)

display(aMaze) #this will show you that homer moved

If anyone could help me with this, it would be very much appreciated.
Thank you.:)

Editor's note: code tags added

Recommended Answers

All 3 Replies

Lisa says:

Please put code samples in between [code=Python] and [/code] brackets so it displays properly.

As near as I can tell, moveHomer() returns a pair (row,column) and you are trying to unpack that into a 4-tuple. That just won't work.

thanks I managed to figure it out. :)

b04e3ian, please use 4 spaces per indentation and try not to exceed 72 characters per code line, it will make your code much more readable for all of us. Good luck with your game and welcome to DaniWeb.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.