Getting a strange IndexError

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Getting a strange IndexError

Postby BackRaw » Thu Jan 29, 2015 8:13 pm

Hi,

whenever I do this (running CS: S):

Syntax: Select all

@SayCommand(config["saycommand_weapons"])
def saycommand_weapons(playerinfo, command, teamonly):
"""
Gets called whenever someone types the saycommand for the weapons menu in the chat.
"""

# send the main menu
menus[0].send(index_from_playerinfo(playerinfo))

# block the message from being shown
return CommandReturn.BLOCK


I get that exception:

Code: Select all

[SP] Caught an Exception:
Traceback (most recent call last):
  File '../addons/source-python/packages/source-python/commands/manager.py', line 148, in __call__
    return_value = callback(*args)
  File '../addons/source-python/packages/source-python/commands/auth.py', line 63, in __call__
    return self.callback(*args)
  File '../addons/source-python/plugins/simpledm/simpledm.py', line 307, in saycommand_weapons
    menus[0].send(index_from_playerinfo(playerinfo))
 
IndexError: list index out of range
Why is that so? Because, I definitely have menus[0]:


The funny thing is, I actually open the weapons menu, and I can choose the weapons and receive them. The code itself works, it seems like the exception is coming out of nowhere. Sometimes it throws the exception and sometimes it doesn't... Can you help me? :)
Attachments
Screen Shot 2015-01-29 at 21.10.40.jpg
Screen Shot 2015-01-29 at 21.10.33.jpg
Screen Shot 2015-01-29 at 21.10.26.jpg
Screen Shot 2015-01-29 at 21.08.38.jpg
Screen Shot 2015-01-29 at 21.08.18.jpg
My Github repositories:

Source.Python: https://github.com/backraw
User avatar
satoon101
Project Leader
Posts: 2703
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Thu Jan 29, 2015 8:25 pm

I notice you don't close you menus on unload, but you do clear the list of menus. This is probably the cause of those errors. Close your menus on unload, either in your unload function or override the list's clear method to do so.
Image
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Thu Jan 29, 2015 8:47 pm

satoon101 wrote:I notice you don't close you menus on unload, but you do clear the list of menus. This is probably the cause of those errors. Close your menus on unload, either in your unload function or override the list's clear method to do so.


Makes sense, thanks.
My Github repositories:

Source.Python: https://github.com/backraw

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 139 guests