Jump to content

list index out of range !!!


Recommended Posts

hello metin2dev community
this is the sysr
 

0617 03:07:26595 :: Traceback (most recent call last):

0617 03:07:26595 ::   File "generateInterface.py", line 1486, in CallEvent

0617 03:07:26595 ::   File "generateInterface.py", line 3868, in ClickButton

0617 03:07:26595 ::   File "uiItemShop.py", line 102, in SelectCategory

0617 03:07:26595 :: IndexError
0617 03:07:26595 :: : 
0617 03:07:26595 :: list index out of range
0617 03:07:26595 :: 


and this is the error list
 

def SelectCategory(self, catId):
		if self.selectedCategory == int(catId):
			return
		self.selectedCategory = int(catId)
		self.categoryList.SetButtonDown(int(catId))
		self.itemList.ClearItems()
		for item in self.items[int(catId)]:
			self.itemList.InsertItem(item[0], item[1], item[2], item[3], item[4], item[5], item[6])

and this is the items list lua

items = {
				[1] = {
						[1] = {299, 1, 30, 1, "x"},


and the game.py and generateinterface.py
in attachment
how can i slove this problem it take from me one week and i dont find the problem

This is the hidden content, please

This is the hidden content, please

  • Metin2 Dev 1
  • Good 2
  • Love 5
Link to comment
Share on other sites

8 minutes ago, Shang said:

oh, and try to do a check if the catId is in the array with this: if self.items.has_key(int(catId)).

Array Is a list theoretical , not a dictionary :D, 'list' no have attribute 'has_key', so that doesn't work.

The check of list value should look like that, a simple version:

if int(catId) in self.items:
	# do something
Link to comment
Share on other sites

hace 15 horas, NeXoN dijo:

 


items = {
				[1] = {
						[1] = {299, 1, 30, 1, "x"},

 

 

hace 1 hora, Tasho dijo:

Array Is a list theoretical , not a dictionary :D, 'list' no have attribute 'has_key', so that doesn't work.

The check of list value should look like that, a simple version:


if int(catId) in self.items:
	# do something

I thought I was blind, but not, I see a dictionary here not a "theorical list".

PS: Try to help not to correct others word.

Link to comment
Share on other sites

1 hour ago, Shang said:

 

I thought I was blind, but not, I see a dictionary here not a "theorical list".

PS: Try to help not to correct others word.

I speaking about python not lua oh my god and what error say.

0617 03:07:26595 :: IndexError
0617 03:07:26595 :: : 
0617 03:07:26595 :: list index out of range
0617 03:07:26595 :: 

Already i give him a option to check it list by catID if exist, you give him "has_key" what is totally wrong.

if int(catId) in self.items:

I was speaking about your "has_key" on list python, how you can explain that if you say "you not was blind".

You should learn bit python (because as i see you didn't know syntax of lua and python), maybe that say you something.

if self.items.has_key(int(catId)):
python 'list' object has no attribute 'has_key'

 

I'm not trying to offense you, but as i say there was a list not a dictionary, because if  was dictionary was get KeyError not list index out of range, or maybe i'm wrong?

@NeXoN

That should solved your problem.

def SelectCategory(self, catId):
	categoryID = int(catId)

	if self.selectedCategory == categoryID or categoryID not in self.items:
		return

	self.selectedCategory = categoryID
	self.categoryList.SetButtonDown(categoryID)
	self.itemList.ClearItems()

	for item in self.items[categoryID]:
		self.itemList.InsertItem(item[0], item[1], item[2], item[3], item[4], item[5], item[6])

 

PS: @Shang

itemsList = []
print (itemsList[999])

#Traceback (most recent call last):
#File "python", line 2, in <module>
#IndexError: list index out of range


itemsDict = {}
print (itemsDict[999])

#Traceback (most recent call last):
#File "python", line 2, in <module>
#KeyError: 999

 

PS: Now i hope you understand what is list and what is dictionary, have a nice day.

Link to comment
Share on other sites

hace 58 minutos, Tasho dijo:

I speaking about python not lua oh my god and what error say.


0617 03:07:26595 :: IndexError
0617 03:07:26595 :: : 
0617 03:07:26595 :: list index out of range
0617 03:07:26595 :: 

Already i give him a option to check it list by catID if exist, you give him "has_key" what is totally wrong.


if int(catId) in self.items:

I was speaking about your "has_key" on list python, how you can explain that if you say "you not was blind".

You should learn bit python (because as i see you didn't know syntax of lua and python), maybe that say you something.


if self.items.has_key(int(catId)):

python 'list' object has no attribute 'has_key'

 

I'm not trying to offense you, but as i say there was a list not a dictionary, because if  was dictionary was get KeyError not list index out of range, or maybe i'm wrong?

@NeXoN

That should solved your problem.


def SelectCategory(self, catId):
	categoryID = int(catId)

	if self.selectedCategory == categoryID or categoryID not in self.items:
		return

	self.selectedCategory = categoryID
	self.categoryList.SetButtonDown(categoryID)
	self.itemList.ClearItems()

	for item in self.items[categoryID]:
		self.itemList.InsertItem(item[0], item[1], item[2], item[3], item[4], item[5], item[6])

 

PS: @Shang


itemsList = []
print (itemsList[999])

#Traceback (most recent call last):
#File "python", line 2, in <module>
#IndexError: list index out of range


itemsDict = {}
print (itemsDict[999])

#Traceback (most recent call last):
#File "python", line 2, in <module>
#KeyError: 999

 

PS: Now i hope you understand what is list and what is dictionary, have a nice day.

I didn't read it was a lua list, i thought it was a python dictionary, sorry sir.

Link to comment
Share on other sites

@Tasho
same thing mr.Tasho
sysr


 

0618 04:07:25464 :: Traceback (most recent call last):

0618 04:07:25464 ::   File "generateInterface.py", line 1486, in CallEvent

0618 04:07:25464 ::   File "generateInterface.py", line 3868, in ClickButton

0618 04:07:25464 ::   File "uiItemShop.py", line 106, in SelectCategory

0618 04:07:25464 :: IndexError
0618 04:07:25464 :: : 
0618 04:07:25465 :: list index out of range
0618 04:07:25465 :: 


this is  CallEvent in line 1486:

    def ClickButton(self, line):
        if line == self.lastLine:
            return
        self.lastLine = line
        if self.event:
            self.event(self.keyDict.get(line, -1))

 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.