Raised This Month: $ Target: $400
 0% 

Index out of bounds


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Podarok
BANNED
Join Date: Jan 2011
Location: Narnia
Old 08-15-2013 , 09:53   Index out of bounds
Reply With Quote #1

So I have got a menu and prices for it and in handler i remove amout of money required to buy item, but console is showing me an error : Index is out of bounds, how can I cope with it ?

Code:
public shopmenu_handler( id, menu, item )  {     if( item == MENU_EXIT )  {         menu_destroy( menu );         return PLUGIN_HANDLED;     }     new money = cs_get_user_money(id)     cs_set_user_money(id, money-str_to_num(g_Cost[item]))            // <----- This Line

Code:
    static const g_Cost[][] = {     { "10000" },        { "13000" },        { "16000" },        { "7500" },         { "7000" },         { "12000" },        { "7500" },         { "15000" },        { "16000" } }
Podarok is offline
~Ice*shOt
Veteran Member
Join Date: Mar 2009
Location: Lithuania
Old 08-15-2013 , 09:59   Re: Index out of bounds
Reply With Quote #2

how much items are?
~Ice*shOt is offline
Send a message via Skype™ to ~Ice*shOt
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 08-15-2013 , 10:00   Re: Index out of bounds
Reply With Quote #3

What is the value of item? IIRC, the New Menu style does not use a Zero based item scale, so you would need to cope with that.
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 08-15-2013 , 10:08   Re: Index out of bounds
Reply With Quote #4

Yami is right, use str_to_num( g_Cost[ item - 1 ] ).
Backstabnoob is offline
Podarok
BANNED
Join Date: Jan 2011
Location: Narnia
Old 08-15-2013 , 10:34   Re: Index out of bounds
Reply With Quote #5

Quote:
Originally Posted by YamiKaitou View Post
What is the value of item? IIRC, the New Menu style does not use a Zero based item scale, so you would need to cope with that.
If I press 0 - aka Exit, it shows me this error...

Quote:
Originally Posted by Backstabnoob View Post
Yami is right, use str_to_num( g_Cost[ item - 1 ] ).
Also this is not right.

Last edited by Podarok; 08-15-2013 at 10:34.
Podarok is offline
guipatinador
SourceMod Donner Party
Join Date: Oct 2009
Location: Poortugal
Old 08-15-2013 , 10:37   Re: Index out of bounds
Reply With Quote #6

Quote:
Originally Posted by Backstabnoob View Post
Yami is right, use str_to_num( g_Cost[ item - 1 ] ).
No.
If I press key one, item = 0.
g_Cost[ 0 ] = 10000
guipatinador is offline
Podarok
BANNED
Join Date: Jan 2011
Location: Narnia
Old 08-15-2013 , 10:41   Re: Index out of bounds
Reply With Quote #7

Quote:
Originally Posted by guipatinador View Post
No.
If I press key one, item = 0.
g_Cost[ 0 ] = 10000
Yes thats what I am talking about. This error occurs when u press 0. Aka Exit!
Podarok is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 08-15-2013 , 10:43   Re: Index out of bounds
Reply With Quote #8

Quote:
Originally Posted by Podarok View Post
Yes thats what I am talking about. This error occurs when u press 0. Aka Exit!
No it doesn't. You have caught the MENU_EXIT. If you believe it is the other way, then DEBUG it
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Podarok
BANNED
Join Date: Jan 2011
Location: Narnia
Old 08-15-2013 , 14:46   Re: Index out of bounds
Reply With Quote #9

Quote:
Originally Posted by YamiKaitou View Post
No it doesn't. You have caught the MENU_EXIT. If you believe it is the other way, then DEBUG it
I opened 2 windows, CS and My Remote Connection to the server i pressed every key on the menu and only when I pressed 0 aka Exit this error occured.. I was also wondered why because as u said i have caught the MENU_EXIT ? Maybe I should do it like this : if(item == -1)... ?
Podarok is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 08-15-2013 , 14:54   Re: Index out of bounds
Reply With Quote #10

This is the only way to know what the true value of item is

Code:
public shopmenu_handler( id, menu, item )  { server_print("item == %d", item);     if( item == MENU_EXIT )  {         menu_destroy( menu );         return PLUGIN_HANDLED;     } server_print("item was not MENU_EXIT");     new money = cs_get_user_money(id)     cs_set_user_money(id, money-str_to_num(g_Cost[item]))            // <----- This Line
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:25.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode