Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Trying to make sprites move? help?
Index -> Programming, Python -> Python Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
munt4life




PostPosted: Sun Dec 25, 2011 1:02 pm   Post subject: Trying to make sprites move? help?

So far I have these pictures, i have 36 of them, and im a bit confused on whether i need to put all the pictures into one list
It always seems to give me a list out of index error, if someone could help me through this, it would greatly be appreciated.
link =[]
for i in range(9):
link[i] = image.load("linkdown" + str(i+1) + ".bmp")
link.append(link[i])
for i2 in range(10,18):
link[i2] = image.load("linkright" + str(i2-9) + ".bmp")
link.append(link[i2])
for i3 in range(19,27):
link[i3] = image.load("linkleft"+str(i3-18) + ".bmp")
link.append(link[i3])
for i4 in range(28,36):
link[i4] = image.load("linkup"+str(i4-27) + ".bmp")
link.append(link[i4])
def linkDown():
screen.blit(link[i],0,0)
Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: Thu Jan 05, 2012 5:15 pm   Post subject: Re: Trying to make sprites move? help?

I think this is the problem.
code:
link =[]
link[i] = image.load("linkdown" + str(i+1) + ".bmp")
link.append(link[i])

First you create an empty list (line 1), then you assign a value to an element of this empty list (line 2) and finally add this value to the list (line 3). But an empty list has no elements so you can't assign one a value (hence the index out of range error). Consider simply appending the value to the list directly.

Alternately, if your goal was to separate the images into lists within the main list, then append some empty lists to the main list, then append values to those lists.
Display posts from previous:   
   Index -> Programming, Python -> Python Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: